/****************************/ /* 関数(様々な引数) */ /* coded by Y.Suganuma */ /****************************/ #include <iostream> #include <vector> using namespace std; template <class cl> vector<cl> range(cl start, cl end, cl step = 1) { vector<cl> x; if (step > 0) { for (cl i1 = start; i1 < end; i1 += step) x.push_back(i1); } else { for (cl i1 = start; i1 > end; i1 += step) x.push_back(i1); } return x; } int main() { for (auto a : range(1, 4)) cout << a << " "; cout << endl; for (auto a : range(10, 0, -1)) cout << a << " "; cout << endl; for (auto a : range(1.3, 4.7, 1.1)) cout << a << " "; cout << endl; return 0; }
1 2 3 10 9 8 7 6 5 4 3 2 1 1.3 2.4 3.5 4.6