Last active
December 18, 2015 21:59
-
-
Save socantre/5851322 to your computer and use it in GitHub Desktop.
for_each_i: algorithm to iterator over a range, with an index.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class InputIterator, class Function> | |
Function for_each_i(InputIterator first, InputIterator last, Function f) { | |
using index_type = std::iterator_traits<InputIterator>::difference_type i; | |
for (index_type i {}; first!=last; ++first, ++i) { | |
f(*first, i); | |
} | |
return std::move(f); | |
} | |
/* | |
25.1 | |
add: | |
template<class InputIterator, class Function> | |
Function for_each_i(InputIterator first, InputIterator last, Function f); | |
25.2.4 | |
add: | |
template<class InputIterator, class Function> | |
Function for_each_i(InputIterator first, InputIterator last, Function f); | |
Effects: ... for_each_i passes, as a second argument to f, an object of type iterator_traits<InputIterator>::difference_type, which is initially value initialized and incremented after each application of f. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment