Skip to content

Instantly share code, notes, and snippets.

@fabiogaluppo
Created December 7, 2015 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiogaluppo/21970867753efa1c2346 to your computer and use it in GitHub Desktop.
Save fabiogaluppo/21970867753efa1c2346 to your computer and use it in GitHub Desktop.
template<typename InputIterator, typename T, typename Function>
T fold(InputIterator first, InputIterator last, T init, Function f)
{
T acc{ init };
while (first != last)
{
acc = f(acc, *first);
++first;
}
return acc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment