Last active
August 29, 2015 14:05
-
-
Save DieHertz/ac4d926d74b30c6a7eea to your computer and use it in GitHub Desktop.
Android created Gist
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 T> struct range_iterator { | |
T pos; | |
T& operator*() { return pos; } | |
range_iterator& operator++() { return ++pos, *this; } | |
bool operator!=(const range_iterator& other) { return pos != other.pos; } | |
}; | |
template<typename T> struct range_wrapper { | |
using iterator = range_iterator<T>; | |
T begin_; | |
T end_; | |
iterator begin() { return { begin_ }; } | |
iterator end() { return { end_ }; } | |
}; | |
template<typename T1, typename T2> auto range(T1 begin, T2 end) { | |
using common_type = typename std::common_type<T1, T2>::type; | |
return { static_cast<common_type>(begin), static_cast<common_type>(end) }; | |
} | |
int main() { | |
for (auto val : range(0, 10)) print(val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment