This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/49734] Adding using std::for_each inconsistent with return value


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]