From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7789 invoked by alias); 23 Jul 2005 20:07:51 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 7732 invoked by uid 48); 23 Jul 2005 20:07:48 -0000 Date: Sat, 23 Jul 2005 20:08:00 -0000 From: "squell at alumina dot nl" To: gcc-bugs@gcc.gnu.org Message-ID: <20050723200746.22634.squell@alumina.nl> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug libstdc++/22634] New: partial_sum is too constrained X-Bugzilla-Reason: CC X-SW-Source: 2005-07/txt/msg02986.txt.bz2 List-Id: 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