Boost logo

Boost Users :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2007-03-20 12:07:13


Matthew Bray skrev:
> I have a problem with the current ptr_sequence interface, according to
> the documentation point #7 at this location:
> http://www.boost.org/libs/ptr_container/doc/examples.html#transferring-ownership-of-pointers-between-different-pointer-containers
>
> it should be possible to write something such as this
>
> ptr_list<X> list; ptr_vector<X> vec;
>
> list.transfer( list.begin(), vec.begin(), vec );
> vec.transfer( vec.end(), list.begin(), list.end(), list );
>
> i.e. given a U<T> and a V<T> I should be able to perform transfer
> operations in either direction.
>
> However given a suitable X this code fails to compile on VC++ 8 as well
> as GCC 3.4. Indeed any attempt to transfer between different
> ptr_sequence types (e.g. ptr_deque<X> to ptr_vector<X>) fails to
> compile. Looking at the implementation of ptr_sequence it appears easy
> to see why this is the case.

I think the documentation is incorrect.

Could you check if this has been fixed in 1.34?

-Thorsten

Here's the code for 1.34:

         template< class PtrSeqAdapter >
         void transfer( iterator before,
                        BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator
first,
                        BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator
last,
                        PtrSeqAdapter& from ) // strong
         {
             BOOST_ASSERT( (void*)&from != (void*)this );
             if( from.empty() )
                 return;
             this->c_private().
                 insert( before.base(),
                         first.base(), last.base() ); // strong
             from.c_private().erase( first.base(),
                                     last.base() ); // nothrow
         }

         template< class PtrSeqAdapter >
         void transfer( iterator before,
                        BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator
object,
                        PtrSeqAdapter& from ) // strong
         {
             BOOST_ASSERT( (void*)&from != (void*)this );
             if( from.empty() )
                 return;
             this->c_private().
                 insert( before.base(),
                         *object.base() ); // strong
             from.c_private().erase( object.base() ); // nothrow
         }

         template< class PtrSeqAdapter >
         void transfer( iterator before, PtrSeqAdapter& from ) // strong
         {
             BOOST_ASSERT( (void*)&from != (void*)this );
             if( from.empty() )
                 return;
             this->c_private().
                 insert( before.base(),
                         from.begin().base(), from.end().base() ); // strong
             from.c_private().clear(); //
nothrow
         }


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net