Created
August 12, 2015 01:41
-
-
Save whoshuu/246b10cdd7341895453f to your computer and use it in GitHub Desktop.
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
#include <vector> | |
class range { | |
public: | |
typedef std::vector<long>::const_iterator const_iterator; | |
range(long end) : range(0, end) {} | |
range(long begin, long end, long step = 1) { | |
long diff = end - begin; | |
if ((diff > 0 && step > 0) || | |
(diff < 0 && step < 0)) { | |
while(begin != end) { | |
range_.push_back(begin); | |
begin += step; | |
} | |
} | |
} | |
const_iterator begin() const { | |
return range_.begin(); | |
} | |
const_iterator end() const { | |
return range_.end(); | |
} | |
private: | |
std::vector<long> range_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment