所以我只在 std::set 上遇到了一个奇怪的迭代器错误:我无法在没有编译错误的情况下在迭代器上做一个简单的事情,比如 (it + 1) 尝试自己编译:
void setBug()
{
std::set<int> values;
for (auto it = values.cbegin();
it != values.cend(); ++it) {
if ((it + 1) != values.end())
values.insert(*it / *(it + 1));
}
}
错误:二进制表达式的无效操作数 ('std::_ 1:: _tree_const_iterator *, long>' 和 'int') if ((it + 1) != values.end())
错误:二进制表达式的无效操作数 ('std::_ 1:: _tree_const_iterator *, long>' 和 'int') values.insert(*it / *(it + 1));
编译器版本:Apple LLVM 5.0 版(clang-500.2.79)(基于 LLVM 3.3svn)目标:x86_64-apple-darwin13.1.0 线程模型:posix
我找到了一个肮脏的解决方案: (auto it2 = ++it ; --it) 可行,但这真的很脏......
有人解释一下吗?std::set 坏了吗?
谢谢。