对于我的项目,我需要使循环中的迭代器转到容器中的下一个项目,执行一些操作,然后再次返回到同一个迭代器并继续,但是,由于某种原因既不是advance
也不是next
,然后使用prev
似乎工作。那么我怎样才能获得下一个迭代器并返回到上一个迭代器呢?
我收到以下错误消息:
no matching function for call to 'next(int&)'
no type named 'difference_type' in 'struct std::iterator_traits<int>'
谢谢!
template<class T>
void insert_differences(T& container)
{
for(auto it : container){
// do some operations here
//advance(it,1);
it = next(it);
// do some operations here
//advance(it, -1);
it = prev(it);
}
}