Created
October 13, 2015 01:06
-
-
Save thiagomg/ffbe23711b8abc5c001d to your computer and use it in GitHub Desktop.
Range loops - Writing safe
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 { | |
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