While its not provided by C++11, you can write your own view or use the one from boost:
#include <boost/range/irange.hpp>
#include <iostream>
int main(int argc, char **argv)
{
for (auto i : boost::irange(1, 10))
std::cout << i << "
";
}
Moreover, Boost.Range
contains a few more interesting ranges which you could find pretty useful combined with the new for
loop. For example, you can get a reversed view.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…