n={0,1,…,n-1} in C++
问题 The formal definition (in set theory) of a natural number n is as follows: 0 is the empty set 1 = {0} n = {0,1,...,n-1} I think this would make some C++ code much simpler, if I was allowed to do this: for (int n : 10) cout << n << endl; and it printed numbers from 0 to 9. So I tried doing the following, which doesn't compile: #include <iostream> #include <boost/iterator/counting_iterator.hpp> boost::counting_iterator<int> begin(int t) { return boost::counting_iterator<int>(0); } boost: