Functional C++

From Tuxamito
Revision as of 09:23, 11 December 2014 by Daniel (talk | contribs)
Jump to: navigation, search


Function Equivalence
Haskell C++
map for_each
foldl accumulate
foldr accumulate
filter copy_if
replicate fill_n

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;
}