Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: C++11 中是否有一个范围类用于基于范围的 for 循环?
即是否有一个带有迭代器的标准范围可以取消对整数的引用?我正在考虑这样的事情:
for (int i : rangeTo(10)) { ... } for (int i : rangeFromTo(10, 20)) { .... }
不,但有boost::irange:
boost::irange
#include <boost/range/irange.hpp> ... for (auto i : boost::irange(10, 20)) { std::cout << i << ' '; }
和boost::counting_range
boost::counting_range
for (auto i : boost::counting_range(10, 20)) { std::cout << i << ' '; }
不同之处在于您可以添加一个步骤,对于boost::irange(10, 20, 2).
boost::irange(10, 20, 2)