$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Sam Lievesley (sam.lievesley_at_[hidden])
Date: 2007-08-11 09:47:20
Hi,
I think I've found a bug when trying to use boost::ptr_set that stops my code from compiling
Pseudo code to reproduce the compiler error:
    // declare a ptr_set
    typedef boost::ptr_set<CTask> CTasks;
    CTasks iTasks;
    void DestroyTask(const CTask& aTask)
    {
        iTasks.erase(iTasks.find(aTask));                // Compiles ok
        iTasks.erase(aTask);                                  // Compiler complains
    }
The error line from the compiler is 
c:\program files\boost\boost_1_34_0\boost\ptr_container\detail\associative_ptr_container.hpp(106) : error C2664: 'std::_Tree<_Traits>::iterator std::_Tree<_Traits>::find(void *const &)' : cannot convert parameter 1 from 'const CTask' to 'void *const &'
Taking a look in associative_ptr_container.hpp
        size_type erase( const key_type& x ) // nothrow
        {
            iterator i( this->c_private().find( x ) );  // nothrow
            if( i == this->end() )                      // nothrow
                return 0u;                              // nothrow
            this->remove( i );                          // nothrow
            return this->c_private().erase( x );        // nothrow
        }
This function should be:
        size_type erase( const key_type& x )                                            // nothrow
        {
            iterator i( this->c_private().find( const_cast<key_type*>(&x) ) );      // nothrow
            if( i == this->end() )                                                                     // nothrow
                return 0u;                                                                               // nothrow
            this->remove( i );                                                                         // nothrow
            return this->c_private().erase( const_cast<key_type*>(&x) );          // nothrow
        }
It now compiles! As I'm not a boost developer I'd appreciate if someone responsible could verify the fix and submit it if its ok ;-)
thanks
Sam