bug-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: g++ numerics accumulate


From: Mumit Khan
Subject: Re: g++ numerics accumulate
Date: 16 Mar 2001 17:46:46 GMT

[ posted to gnu.g++.bug with courtesy copy to Dale Gerdemann ]

In article <address@hidden>,
Dale Gerdemann <address@hidden> wrote:
>Hello,
>
>Here's a little program that compiled fine at:
>
>   http://www.comeaucomputing.com/tryitout/
>
>With g++ 2.59.2 it produces a long incomprehensible error message:

I don't see how this code can compile without errors on any compiler, 
but you're right that the diagnostic gcc spits out is rather 
incomprehensible.  Good news is that gcc-3.0, the next major release
of GCC, will provide a much more succinct and almost understandable
diagnostic.

>int
>get_second(int val, map<string,int>::const_iterator& iter) {
>  return val + iter->second;
>}

This really doesn't make much sense if you think about it. The variant
of std::accumulate you're using passes two parameters to your binary
operator function -- the initial value and whatever value it gets by
*dereferencing* the iterator, not the iterator itself. For the case of
a std::map, dereferencing the iterator gives you a std::map::value_type,
which is just a shorter way of saying std::pair<...>. 

Try:

int
get_second(int val, const map<string,int>::value_type& item) {
  return val + item.second;
}

Regards,
Mumit




reply via email to

[Prev in Thread] Current Thread [Next in Thread]