我需要 Haskell 的类似物foldl
功能可折叠任何 STL 容器。预期签名如下:
template Iterator, FoldingFunction, Result
Result foldl(
Iterator begin,
Iterator end,
FoldingFunction f,
Result initValue);
标准STL没有这样的功能。做Boost有什么?
我知道它实现起来非常简单,但我想知道是否有任何现成的标准化实现。
还有一个问题:您通常如何在 C++/STL 中折叠数据列表?
STL确实有这样的功能:std::accumulate http://www.cppreference.com/wiki/stl/algorithm/accumulate。然而它在标题中<numeric>
, not <algorithm>
.
实际上关于“折叠”的维基百科页面 http://en.wikipedia.org/wiki/Fold_%28higher-order_function%29#Implementation已经列出了foldl
/foldr
大多数编程语言(包括 C++)上的函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)