基于C++ 11范围的for循环取消引用迭代器.这是否意味着使用它没有意义boost::adaptors::indexed?例:
boost::counting_range numbers(10,20);
for(auto i : numbers | indexed(0)) {
cout << "number = " i
/* << " | index = " << i.index() */ // i is an integer!
<< "\n";
}
Run Code Online (Sandbox Code Playgroud)
我总是可以使用计数器,但我喜欢索引迭代器.
该问题已在 Boost 1.56(2014 年 8 月发布)中修复;该元素间接位于value_typewithindex()和value()成员函数后面。
示例:http ://coliru.stacked-crooked.com/a/e95bdff0a9d371ea
auto numbers = boost::counting_range(10, 20);
for (auto i : numbers | boost::adaptors::indexed())
std::cout << "number = " << i.value()
<< " | index = " << i.index() << "\n";
Run Code Online (Sandbox Code Playgroud)