Skip to content

Instantly share code, notes, and snippets.

@whoshuu
Created August 12, 2015 01:41
Show Gist options
  • Save whoshuu/246b10cdd7341895453f to your computer and use it in GitHub Desktop.
Save whoshuu/246b10cdd7341895453f to your computer and use it in GitHub Desktop.
#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