Difference between revisions of "Functional C++"
Line 11: | Line 11: | ||
|- | |- | ||
|foldl | |foldl | ||
+ | |accumulate | ||
+ | |- | ||
+ | |foldr | ||
|accumulate | |accumulate | ||
|- | |- | ||
Line 19: | Line 22: | ||
|fill_n | |fill_n | ||
|} | |} | ||
+ | |||
+ | == map == | ||
+ | |||
+ | == foldl == | ||
+ | |||
+ | == foldr == | ||
+ | |||
+ | == filter == | ||
+ | |||
+ | == replicate == | ||
+ | |||
+ | <syntaxhighlight lang="cpp"> | ||
+ | template <class OutputIterator, class Size, class T> | ||
+ | OutputIterator fill_n (OutputIterator first, Size n, const T& val) | ||
+ | { | ||
+ | while (n>0) { | ||
+ | *first = val; | ||
+ | ++first; --n; | ||
+ | } | ||
+ | return first; | ||
+ | } | ||
+ | </syntaxhighlight> |
Revision as of 09:23, 11 December 2014
Function Equivalence | |
---|---|
Haskell | C++ |
map | for_each |
foldl | accumulate |
foldr | accumulate |
filter | copy_if |
replicate | fill_n |
Contents
map
foldl
foldr
filter
replicate
template <class OutputIterator, class Size, class T>
OutputIterator fill_n (OutputIterator first, Size n, const T& val)
{
while (n>0) {
*first = val;
++first; --n;
}
return first;
}