boost::ptr_vector and find_if

后端 未结 3 2002
心在旅途
心在旅途 2021-01-28 18:53

I have a class:

//header file
class CMDatabase
{
    class Try;
    typedef boost::shared_ptr TryPtr;
    typedef boost::ptr_vector TryVect         


        
3条回答
  •  梦谈多话
    2021-01-28 19:36

    Just for sake of completeness, the following statement is wrong! Thanks to Matthieu M. to point out my mistake!

    On dereferencing an iterator of the boost pointer container you will get the pure pointer to the element. So you can try to dereference the pure pointer you get through the iterator:

    CMDatabase::TryVectorIterator it =
      find_if(updateTry.begin(), updateTry.end(), bind1st(mem_fun(&CMDatabase::Try::equal), **i));
    

    Where the following is still correct ;)

    Or you can use the the operator[] implementation of the boost::ptr_vector which will return a reference to the element:

    for (std::size_t i = 0, l = ; defaultTry.size(); ++i) {
      CMDatabase::TryVectorIterator it = std::find_if(
        updateTry.begin(),
        updateTry.end(),
        std::bind1st(std::mem_fun(&CMDatabase::Try::equal), defaultTry[i])
      );
    }
    

    Hope this helps.

提交回复
热议问题