#include <vector>
std::vector<int> Range(int from, int to, int step = 1) {
std::vector<int> range;
if (step > 0) {
for(int i = from; i < to; i += step) {
range.push_back(i);
}
} else if (step < 0) {
for(int i = from; i > to; i += step) {
range.push_back(i);
}
}
return range;
}
I don't like code duplication in my implementation, because I have two almost identical blocks. Is it possible to avoid it?