This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/22634] New: partial_sum is too constrained
- From: "squell at alumina dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jul 2005 20:07:48 -0000
- Subject: [Bug libstdc++/22634] New: partial_sum is too constrained
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Say, we're running std::partial_sum, where the output type is 'wider' than
the input. E.g,
char in_array[4] = { 96, 96, 96, 96 };
int out_array[4];
partial_sum(in_array, in_array+4, out_array);
This "should" be:
int out_array[4] = { 96, 96+96, 96+96+96, 96+96+96+96 };
This is a problem since partial_sum obviously uses an accumulator to hold
the intermediate result, but it uses the input iterator's value_type to
determine the type of the accumulator. So the result in the above case will
be an array with the values 96, -64, 32, -128 (with 8bit signed char).
More involved cases, where the input value_type and output_value type are
incompatible, won't even compile.
I have taken the partial_sum from bits/stl_numeric.h (distributed with DJGPP's
version of g++ 4.01) and produced a work-around solution for this which I
think works correctly and is portable. Note that I reformatted the code and
removed the "gxx" bits, so the attached code is intended as a concept only.
Summary; the solution uses template argument type deduction to determine the
type of accumulator to be used.
--
Summary: partial_sum is too constrained
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: squell at alumina dot nl
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=22634