Created
November 4, 2015 05:02
-
-
Save kovrov/13a14e8339c5a509fec8 to your computer and use it in GitHub Desktop.
Range-based for loop template
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
template <typename T> | |
struct Range { | |
T *_begin, *_end; | |
T *begin() { return _begin; } | |
T *end() { return _end; } | |
}; | |
template <typename T> | |
Range<T> make_range(T *begin, size_t count) | |
{ | |
return begin ? Range<T> { begin, begin + count } : Range<T> { nullptr, nullptr }; | |
} | |
for (auto item_copy : make_range(data_ptr, count)) {} | |
for (auto &item_ref : make_range(data_ptr, count)) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment