-
-
Save shahin-dev/a653293d5862527828bca2f4fc571841 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