Created
December 12, 2018 04:26
-
-
Save MikuroXina/83197702598b0abdd39c4505eab9ef2f to your computer and use it in GitHub Desktop.
Indexed for each in C++
This file contains hidden or 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
#ifndef FOR_INDEXED_LIB | |
#define FOR_INDEXED_LIB | |
// Usage: for_indexed(begin, end, [](auto &e, auto i) { ~: }); | |
template<class ForwardIterator, class Func> | |
void for_indexed(ForwardIterator head, ForwardIterator tail, Func func) { | |
size_t i = 0; | |
for (auto it = head; it != tail; ++it, ++i) func(*it, i); | |
} | |
#endif // FOR_INDEXED_LIB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment