【发布时间】:2016-10-31 00:02:28
【问题描述】:
我正在(前向)迭代一个 std::map 并想知道迭代器是否指向 倒数第二个 元素。我似乎无法在任何地方找到如何做到这一点。
我有:
bool
isSecondLastFile(const TDateFileInfoMap::const_iterator &tsFile)
{
TDateFileInfoMap::reverse_iterator secondLastIt = mFileInfoMap.rbegin() + 1;
return (tsFile == secondLastIt);
}
TDateFileInfoMap 是 std::map
我明白了:
error: no match for ‘operator==’ in ‘tsFile == secondLastIt’
/usr/lib/gcc/i686-redhat-linux/4.4.7/../../../../include/c++/4.4.7/bits/stl_tree.h:287: note: candidates are: bool std::_Rb_tree_const_iterator<_Tp>::operator==(const std::_Rb_tree_const_iterator<_Tp>&) const [with _Tp = std::pair<const long int, TFileInfo>]
这是否意味着我无法比较正向和反向迭代器?
如何判断前向迭代器是否指向倒数第二个元素?
【问题讨论】:
-
tsFile + 2 == mFileInfoMap.end()怎么样?
标签: c++ dictionary iterator stdmap reverse-iterator