Cuch, I actually like the std::accumulate version better in any case -- it expresses the intent more clearly.Performance benefits could convince me for the std::for_each with C++11 lambda solution, but I don't see how it could be faster?If anything, syntax-wise, Boost.Range (2.0) looks more user-friendly:
http://www.boost.org/doc/libs/release/l ... mlalthough it's also not faster, and in one complex case it turned out to be slower than the alternative:
http://stackoverflow.com/questions/3204 ... ts-in-aI'd also prefer identity_element of plus functor instead of hard-coded 0.0, like the one in STL:
http://www.sgi.com/tech/stl/MonoidOpera ... tion.hsome examples:
http://stlab.adobe.com/identity__elemen ... ts.htmlI'm actually a bit surprised that identity_element isn't in C++11 standard, remember there was a couple of STL elements that got there (like iota), apparently it wasn't one of them.Also a bit strange that it's only in the Boost.ICL (and, I think, Boost.Graph), not on a more general level.If anything, I suppose we can always ship ours, perhaps w/ some simpler wrapper around Boost.Range's accumulate with init=identity_element by default (just call it qfcl::sum) -- if there's a need.Then, we can just write:double sum = qfcl::sum(arr);