Skip to content

Instantly share code, notes, and snippets.

@zheplusplus
Last active August 29, 2015 14:10
Show Gist options
  • Save zheplusplus/f52a3d2b2174e1420149 to your computer and use it in GitHub Desktop.
Save zheplusplus/f52a3d2b2174e1420149 to your computer and use it in GitHub Desktop.
C++0x for_each with index
template <typename Iterator, typename Function>
Function for_each_i(Iterator begin, Iterator end, Function f)
{
typedef decltype(*begin) value_type;
int i = 0;
return std::move(std::for_each(begin, end, [&](value_type& e) {f(i++, e);}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment