c++ - implicit promotion to avoid overflow in std::partial_sum -
This code suffers from overflow because the intermediate result type is not dependent on the destination type:
vector & lt; Uint8_t & gt; pay raise; ... vector & lt; Uint32_t & gt; Increasing (increments.size ()); Partial_sum (increments.begin (), increments.end (), increasing; beta ());According toHowever, this does (GCC 4.2):
partial_sam (increments.begin (), increments.end (), increasing. ), Plus & lt; uint32_t & gt; ());
plus <
Edit: I'm very addictive. After a short break, I sat back and checked the implementation of this:
/ * Input_utetter :: value_type * / __value = __binary_op (__ value, * __ earlier); * ++ __ Results = __value;
I think it's not compliant, so I'll look at the latest version and maybe file a bug ... and here we are going:
<
"post-text" itemprop = "text"> ,
partial_sum
has been completely redefined since the n3000 (latest release): < / P>Effect: Enter the value type of InputIterator to be VT. For a non-vacancy category, one initializes one type of accumulation of VT type with AC and * results = AC does for every iterator in order of [first + 1, final] in order, acc to acc = Acc + * i or acc = binary_op (acc, * i) and it is assigned * (result + (i - first)). .
and
'Wide' behavior can be achieved by typing a custom proxy iterator, which is to some extent included.
I can not really see the benefit of working like this, reading fault report, I do not see any propriety except
algorithms intent to input To use the type of instructor, they have to calculate.
Array
Edit: I went ahead and implemented a detailed input iterator. Works as advertised.
template & lt; Class base, class fissure & gt; Straight Widen_iter: Iterator & lt; Input_iterator_tag, broad & gt; {Base B; Widen_iter (base const and inb = base): B (inb) {} Extensively Operator * () const {Return fissure (* b); } Comprehensive const * operator- & gt; () Const {broad t (* b), * ta = & amp; T; Returns; } Widen_iter and operator ++ () {++ b; Return * This; } Widen_iter operator ++ (int) {widen_iter t = * this; ++ B; Return T; } BULL operator == (fourpence_cut b & amp; r) const {Return B == RB; } Bool Operator! = (Twenty-Four Sectors & amp; R) const {Return B! = RB; }}; The template's & lt; Square broad, class base & gt; Widen_iter & lt; Base, Comprehensive & gt; Grammar (base B) {return widen_iter & lt; Base, Comprehensive & gt; (B); }
may be very low if there is a normal filter-by-factor input iterator.