public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/22634] New: partial_sum is too constrained
@ 2005-07-23 20:08 squell at alumina dot nl
  2005-07-23 20:09 ` [Bug libstdc++/22634] " squell at alumina dot nl
                   ` (14 more replies)
  0 siblings, 15 replies; 18+ messages in thread
From: squell at alumina dot nl @ 2005-07-23 20:08 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 18+ messages in thread
[parent not found: <bug-22634-11044@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2006-02-04 20:53 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-23 20:08 [Bug libstdc++/22634] New: partial_sum is too constrained squell at alumina dot nl
2005-07-23 20:09 ` [Bug libstdc++/22634] " squell at alumina dot nl
2005-07-23 21:28 ` bangerth at dealii dot org
2005-07-23 23:50 ` squell at alumina dot nl
2005-07-24  0:22 ` bangerth at dealii dot org
2005-07-24  3:01 ` squell at alumina dot nl
2005-07-24  3:27 ` gdr at integrable-solutions dot net
2005-07-24  3:32 ` gdr at integrable-solutions dot net
2005-07-24 10:11 ` pcarlini at suse dot de
2005-07-24 12:41 ` gdr at integrable-solutions dot net
2005-07-24 17:18 ` squell at alumina dot nl
2005-07-24 17:26 ` gdr at integrable-solutions dot net
2005-07-25  9:51 ` chris at bubblescope dot net
2005-07-25 10:24 ` gdr at integrable-solutions dot net
2005-07-25 14:02 ` squell at alumina dot nl
2005-07-25 14:17 ` squell at alumina dot nl
     [not found] <bug-22634-11044@http.gcc.gnu.org/bugzilla/>
2006-02-04 12:45 ` squell at alumina dot nl
2006-02-04 20:53 ` pcarlini at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).