Skip to content

Instantly share code, notes, and snippets.

@kovrov
Created November 4, 2015 05:02
Show Gist options
  • Save kovrov/13a14e8339c5a509fec8 to your computer and use it in GitHub Desktop.
Save kovrov/13a14e8339c5a509fec8 to your computer and use it in GitHub Desktop.
Range-based for loop template
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