Since C++11 introduced the range-based for loop (range-based for in c++11), what is the neatest way to express looping over a range of integers?
Instead of
While its not provided by C++11, you can write your own view or use the one from boost:
#include
#include
int main(int argc, char **argv)
{
for (auto i : boost::irange(1, 10))
std::cout << i << "\n";
}
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.