Last active
May 20, 2018 22:19
-
-
Save kvk1920/4459158464bc3017e8bcca088379c38a to your computer and use it in GitHub Desktop.
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 <typename Iterator, typename IteratorType> | |
struct __advance { | |
static Iterator f(Iterator it, int n) { | |
while (n > 0) { ++it; --n; } | |
while (n < 0) { --it; ++n; } | |
return it; | |
} | |
}; | |
template <typename Iterator> | |
struct __advance<Iterator, std::random_access_iterator_tag> { | |
static Iterator f(Iterator it, int n) { | |
return it + n; | |
} | |
}; | |
template <typename Iterator> | |
Iterator advance(Iterator it, int n) { | |
return | |
__advance | |
< | |
Iterator, | |
typename std::iterator_traits<Iterator>::iterator_category | |
>::f(it, n); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment