And*_*rey 26 c++ boost stl fold
我需要一个Haskell foldl
函数的模拟来折叠任何STL容器.预期签名如下:
template Iterator, FoldingFunction, Result
Result foldl(
Iterator begin,
Iterator end,
FoldingFunction f,
Result initValue);
Run Code Online (Sandbox Code Playgroud)
标准STL没有这样的功能.是否加速有什么?
我知道它实现起来非常简单,但我想知道是否有任何现成的标准化实现.
还有一个问题:你通常如何在C++/STL中折叠数据列表?
ken*_*ytm 42
STL确实有这样的功能:std::accumulate
.但是,它在标题中<numeric>
,而不是<algorithm>
.
实际上,"Fold"上的维基百科页面已经在大多数编程语言中列出了foldl
/ foldr
functions,包括C++.