STL迭代器重置

PSI*_*Alt 2 c++ iterator stl

我尝试重用一个STL迭代器,但找不到任何关于此的信息.这段代码有问题:

    std::vector< boost::shared_ptr<Connection> >::iterator poolbegin = pool.begin();
std::vector< boost::shared_ptr<Connection> >::iterator poolend = pool.end();
if( order ) {
    poolbegin = pool.rbegin(); // Here compilation fails
    poolend   = pool.rend();
}
    for( std::vector< boost::shared_ptr<Connection> >::iterator it = poolbegin; it<poolend; it++) {
Run Code Online (Sandbox Code Playgroud)

但得到错误:

错误:'poolbegin = std :: vector <_Tp,_Alloc> :: rbegin()中的'operator ='与_Tp = boost :: shared_ptr,_Alloc = std :: allocator>'不匹配

有没有办法将迭代器重置为新值?像shared_ptr :: reset一样?

Bo *_*son 7

rbegin()返回a reverse_iterator,这是一个与正常情况完全不同的类型iterator.

它们不能彼此分配.