Create a gist now

Instantly share code, notes, and snippets.

Embed
Range loops - Writing safe
template<typename T>
struct range {
range(const T &cont) : _b(cont.begin()), _e(cont.end()) {}
range(typename T::const_iterator b, typename T::const_iterator e) : _b(b), _e(e) {}
typename T::const_iterator &begin() { return _b; }
typename T::const_iterator &end() { return _e; }
private:
typename T::const_iterator _b, _e;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment