This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49734] Adding using std::for_each inconsistent with return value
- From: "marat.buharov at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 13 Jul 2011 15:24:09 +0000
- Subject: [Bug c++/49734] Adding using std::for_each inconsistent with return value
- Auto-submitted: auto-generated
- References: <bug-49734-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49734
--- Comment #3 from MaratIK <marat.buharov at gmail dot com> 2011-07-13 15:23:52 UTC ---
(In reply to comment #2)
> int acc = std::accumulate(c, c + 5, 0);
Thanks. I used overloaded std::accumulate with BinaryOperation (Adder) because
indices for c are in l.
---
struct Adder {
int *cv;
Adder(int *c) : cv(c) {}
int operator()(int x, int y) { return x + cv[y]; }
};
---
int acc = std::accumulate(l, l + 5, 0, Adder(c));
---
With lambda it will be simpler