I need an analog of Haskell's foldl
function to fold any STL containers. Expected signature is like following:
template Iterator, FoldingFunction, Result Result foldl( Iterator begin, Iterator end, FoldingFunction f, Result initValue);
Standard STL has no such function. Does Boost have any?
I know it's pretty simple to implement, but I'd like to know whether there's any ready standardized implementation.
And one more question: how do you usually fold data lists in C++/STL?
STL does have such a function: std::accumulate
. However, it is in the header <numeric>
, not <algorithm>
.
Actually the Wikipedia page on "Fold" already listed the foldl
/foldr
functions on most programming languages, including C++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With