Created
April 20, 2019 05:00
-
-
Save MikuroXina/9c982569cd3c45b239d4ce3cb36e2830 to your computer and use it in GitHub Desktop.
The iterator has index by pair.
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 INDEX_IT_LIB | |
#define INDEX_IT_LIB | |
template<class Iterator> | |
class index_iterator { | |
size_t _i = 0; | |
Iterator _it; | |
public: | |
index_iterator(Iterator it) : _it(it) {} | |
auto operator*() { return std::make_pair(_i, *_it); } | |
auto operator++() { ++_i; ++_it; return std::make_pair(_i, _it); } | |
auto operator+(size_t amount) const { | |
auto adv = index_iterator<Iterator>(_it + amount); | |
adv._i = _i + amount; | |
return adv; | |
} | |
bool operator!=(index_iterator<Iterator> const &r) const { return _it != r._it; } | |
}; | |
#endif // INDEX_IT_LIB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment