epoc32/include/stdapis/boost/ptr_container/detail/reversible_ptr_container.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/ptr_container/detail/reversible_ptr_container.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,678 @@
     1.4 +//
     1.5 +// Boost.Pointer Container
     1.6 +//
     1.7 +//  Copyright Thorsten Ottosen 2003-2005. Use, modification and
     1.8 +//  distribution is subject to the Boost Software License, Version
     1.9 +//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
    1.10 +//  http://www.boost.org/LICENSE_1_0.txt)
    1.11 +//
    1.12 +// For more information, see http://www.boost.org/libs/ptr_container/
    1.13 +//
    1.14 +/*
    1.15 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    1.16 +*/
    1.17 +
    1.18 +#ifndef BOOST_PTR_CONTAINER_DETAIL_REVERSIBLE_PTR_CONTAINER_HPP
    1.19 +#define BOOST_PTR_CONTAINER_DETAIL_REVERSIBLE_PTR_CONTAINER_HPP
    1.20 +
    1.21 +#if defined(_MSC_VER) && (_MSC_VER >= 1200)
    1.22 +# pragma once
    1.23 +#endif
    1.24 +
    1.25 +#include <boost/ptr_container/detail/throw_exception.hpp>
    1.26 +#include <boost/ptr_container/detail/scoped_deleter.hpp>
    1.27 +#include <boost/ptr_container/detail/static_move_ptr.hpp>
    1.28 +#include <boost/ptr_container/exception.hpp>
    1.29 +#include <boost/ptr_container/clone_allocator.hpp>
    1.30 +#include <boost/ptr_container/nullable.hpp>
    1.31 +
    1.32 +#ifdef BOOST_NO_SFINAE
    1.33 +#else
    1.34 +#include <boost/range/functions.hpp>
    1.35 +#endif
    1.36 +
    1.37 +#include <boost/config.hpp>
    1.38 +#include <boost/iterator/reverse_iterator.hpp>
    1.39 +#include <boost/range/iterator.hpp>
    1.40 +#include <boost/utility/enable_if.hpp>
    1.41 +#include <boost/type_traits/is_pointer.hpp>
    1.42 +#include <boost/type_traits/is_integral.hpp>
    1.43 +#include <boost/serialization/split_member.hpp>
    1.44 +#include <algorithm>
    1.45 +#include <exception>
    1.46 +#include <memory>
    1.47 +#include <typeinfo>
    1.48 +#ifdef __SYMBIAN32__
    1.49 +#include <boost/range/begin.hpp>
    1.50 +#include <boost/range/end.hpp>
    1.51 +#endif
    1.52 +
    1.53 +namespace boost
    1.54 +{
    1.55 +    
    1.56 +namespace ptr_container_detail
    1.57 +{
    1.58 +
    1.59 +    template< class T >
    1.60 +    inline T const& serialize_as_const( T const& r )
    1.61 +    {
    1.62 +        return r;
    1.63 +    }
    1.64 +
    1.65 +    template< class CloneAllocator >
    1.66 +    struct clone_deleter
    1.67 +    {
    1.68 +        template< class T >
    1.69 +        void operator()( const T* p ) const
    1.70 +        {
    1.71 +            CloneAllocator::deallocate_clone( p );
    1.72 +        }
    1.73 +    };
    1.74 +
    1.75 +    template< class T >
    1.76 +    struct is_pointer_or_integral
    1.77 +    {
    1.78 +        BOOST_STATIC_CONSTANT(bool, value = is_pointer<T>::value || is_integral<T>::value );
    1.79 +    };
    1.80 +
    1.81 +    struct is_pointer_or_integral_tag {};
    1.82 +    struct is_range_tag {};
    1.83 +
    1.84 +    
    1.85 +    
    1.86 +    template
    1.87 +    < 
    1.88 +        class Config, 
    1.89 +        class CloneAllocator
    1.90 +    >
    1.91 +    class reversible_ptr_container 
    1.92 +    {
    1.93 +    private:
    1.94 +#ifdef  __MWERKS__
    1.95 +        enum { allow_null = Config::allow_null };
    1.96 +#else
    1.97 +        BOOST_STATIC_CONSTANT( bool, allow_null = Config::allow_null );
    1.98 +#endif        
    1.99 +        
   1.100 +        typedef BOOST_DEDUCED_TYPENAME Config::value_type Ty_;
   1.101 +
   1.102 +        template< bool allow_null_values >
   1.103 +        struct null_clone_allocator
   1.104 +        {
   1.105 +            template< class Iter >
   1.106 +            static Ty_* allocate_clone_from_iterator( Iter i )
   1.107 +            { 
   1.108 +                return allocate_clone( Config::get_const_pointer( i ) );
   1.109 +            }
   1.110 +            
   1.111 +            static Ty_* allocate_clone( const Ty_* x )
   1.112 +            {
   1.113 +                if( allow_null_values )
   1.114 +                {
   1.115 +                    if( x == 0 )
   1.116 +                        return 0;
   1.117 +                }
   1.118 +                else
   1.119 +                {
   1.120 +                    BOOST_ASSERT( x != 0 && "Cannot insert clone of null!" );
   1.121 +                }
   1.122 +
   1.123 +                Ty_* res = CloneAllocator::allocate_clone( *x );
   1.124 +                BOOST_ASSERT( typeid(*res) == typeid(*x) &&
   1.125 +                              "CloneAllocator::allocate_clone() does not clone the "
   1.126 +                              "object properly. Check that new_clone() is implemented"
   1.127 +                              " correctly" );
   1.128 +                return res;
   1.129 +            }
   1.130 +            
   1.131 +            static void deallocate_clone( const Ty_* x )
   1.132 +            {
   1.133 +                if( allow_null_values )
   1.134 +                {
   1.135 +                    if( x == 0 )
   1.136 +                        return;
   1.137 +                }
   1.138 +
   1.139 +                CloneAllocator::deallocate_clone( x );
   1.140 +            }
   1.141 +        };
   1.142 +
   1.143 +        typedef BOOST_DEDUCED_TYPENAME Config::void_container_type  Cont;
   1.144 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))    
   1.145 +        typedef  null_clone_allocator<reversible_ptr_container::allow_null> 
   1.146 +                                                                    null_cloner_type;
   1.147 +#else
   1.148 +        typedef null_clone_allocator<allow_null>                    null_cloner_type;
   1.149 +#endif        
   1.150 +        typedef clone_deleter<null_cloner_type>                     Deleter;
   1.151 +
   1.152 +        Cont      c_;
   1.153 +
   1.154 +    public:
   1.155 +        Cont& c_private()                { return c_; }
   1.156 +        const Cont& c_private() const    { return c_; }
   1.157 +
   1.158 +    public: // typedefs
   1.159 +        typedef  Ty_*          value_type;
   1.160 +        typedef  Ty_*          pointer;
   1.161 +        typedef  Ty_&          reference;
   1.162 +        typedef  const Ty_&    const_reference;
   1.163 +        
   1.164 +        typedef  BOOST_DEDUCED_TYPENAME Config::iterator 
   1.165 +                                   iterator;
   1.166 +        typedef  BOOST_DEDUCED_TYPENAME Config::const_iterator
   1.167 +                                   const_iterator;
   1.168 +        typedef  boost::reverse_iterator< iterator > 
   1.169 +                                   reverse_iterator;  
   1.170 +        typedef  boost::reverse_iterator< const_iterator >     
   1.171 +                                   const_reverse_iterator;
   1.172 +        typedef  BOOST_DEDUCED_TYPENAME Cont::difference_type
   1.173 +                                   difference_type; 
   1.174 +        typedef  BOOST_DEDUCED_TYPENAME Cont::size_type
   1.175 +                                   size_type;
   1.176 +        typedef  BOOST_DEDUCED_TYPENAME Config::allocator_type
   1.177 +                                   allocator_type;
   1.178 +
   1.179 +        typedef ptr_container_detail::static_move_ptr<Ty_,Deleter> 
   1.180 +                                   auto_type;
   1.181 +            
   1.182 +    protected: 
   1.183 +            
   1.184 +        typedef ptr_container_detail::scoped_deleter<Ty_,null_cloner_type>
   1.185 +                                   scoped_deleter;
   1.186 +        typedef BOOST_DEDUCED_TYPENAME Cont::iterator
   1.187 +                                   ptr_iterator; 
   1.188 +        typedef BOOST_DEDUCED_TYPENAME Cont::const_iterator
   1.189 +                                   ptr_const_iterator; 
   1.190 +    private:
   1.191 +
   1.192 +        template< class InputIterator >  
   1.193 +        void copy( InputIterator first, InputIterator last ) 
   1.194 +        {
   1.195 +            std::copy( first, last, begin() );
   1.196 +        }
   1.197 +        
   1.198 +        void copy( const reversible_ptr_container& r )
   1.199 +        { 
   1.200 +            copy( r.begin(), r.end() );
   1.201 +        }
   1.202 +        
   1.203 +        void copy_clones_and_release( scoped_deleter& sd ) // nothrow
   1.204 +        {
   1.205 +            BOOST_ASSERT( size_type( std::distance( sd.begin(), sd.end() ) ) == c_.size() );
   1.206 +            std::copy( sd.begin(), sd.end(), c_.begin() );
   1.207 +            sd.release(); 
   1.208 +        }
   1.209 +        
   1.210 +        void insert_clones_and_release( scoped_deleter& sd ) // strong
   1.211 +        {
   1.212 +            c_.insert( sd.begin(), sd.end() );
   1.213 +            sd.release();
   1.214 +        }
   1.215 +
   1.216 +        template< class ForwardIterator >
   1.217 +        void clone_assign( ForwardIterator first, 
   1.218 +                           ForwardIterator last ) // strong 
   1.219 +        {
   1.220 +            BOOST_ASSERT( first != last );
   1.221 +            scoped_deleter sd( first, last );      // strong
   1.222 +            copy_clones_and_release( sd );         // nothrow
   1.223 +        }
   1.224 +
   1.225 +        template< class ForwardIterator >
   1.226 +        void clone_back_insert( ForwardIterator first,
   1.227 +                                ForwardIterator last )
   1.228 +        {
   1.229 +            BOOST_ASSERT( first != last );
   1.230 +            scoped_deleter sd( first, last );
   1.231 +            insert_clones_and_release( sd, end() );
   1.232 +        }
   1.233 +        
   1.234 +        void remove_all() 
   1.235 +        {
   1.236 +            remove( begin(), end() ); 
   1.237 +        }
   1.238 +
   1.239 +    protected:
   1.240 +
   1.241 +        void insert_clones_and_release( scoped_deleter& sd, 
   1.242 +                                        iterator where ) // strong
   1.243 +        {
   1.244 +            //
   1.245 +            // 'c_.insert' always provides the strong guarantee for T* elements
   1.246 +            // since a copy constructor of a pointer cannot throw
   1.247 +            //
   1.248 +            c_.insert( where.base(), 
   1.249 +                       sd.begin(), sd.end() ); 
   1.250 +            sd.release();
   1.251 +        }
   1.252 +
   1.253 +        template< class I >
   1.254 +        void remove( I i )
   1.255 +        { 
   1.256 +            null_policy_deallocate_clone( Config::get_const_pointer(i) );
   1.257 +        }
   1.258 +
   1.259 +        template< class I >
   1.260 +        void remove( I first, I last ) 
   1.261 +        {
   1.262 +            for( ; first != last; ++first )
   1.263 +                remove( first );
   1.264 +        }
   1.265 +
   1.266 +        static void enforce_null_policy( Ty_* x, const char* msg )
   1.267 +        {
   1.268 +            if( !allow_null )
   1.269 +            {
   1.270 +                BOOST_PTR_CONTAINER_THROW_EXCEPTION( 0 == x && "null not allowed", 
   1.271 +                                                     bad_pointer, msg );
   1.272 +            }
   1.273 +        }
   1.274 +
   1.275 +        static Ty_* null_policy_allocate_clone( const Ty_* x )
   1.276 +        {
   1.277 +            return null_cloner_type::allocate_clone( x );
   1.278 +        }
   1.279 +
   1.280 +        static void null_policy_deallocate_clone( const Ty_* x )
   1.281 +        {
   1.282 +            null_cloner_type::deallocate_clone( x );
   1.283 +        }
   1.284 +
   1.285 +    private:
   1.286 +        template< class ForwardIterator >
   1.287 +        ForwardIterator advance( ForwardIterator begin, size_type n ) 
   1.288 +        {
   1.289 +            ForwardIterator iter = begin;
   1.290 +            std::advance( iter, n );
   1.291 +            return iter;
   1.292 +        }
   1.293 +        
   1.294 +    private:
   1.295 +        reversible_ptr_container( const reversible_ptr_container& );
   1.296 +        void operator=( const reversible_ptr_container& );
   1.297 +        
   1.298 +    public: // foundation! should be protected!
   1.299 +        explicit reversible_ptr_container( const allocator_type& a = allocator_type() ) 
   1.300 +         : c_( a )
   1.301 +        {}
   1.302 +        
   1.303 +        template< class PtrContainer >
   1.304 +        explicit reversible_ptr_container( std::auto_ptr<PtrContainer> clone )
   1.305 +          : c_( allocator_type() )                
   1.306 +        { 
   1.307 +            swap( *clone ); 
   1.308 +        }
   1.309 +
   1.310 +    private:
   1.311 +        template< class I >
   1.312 +        void constructor_impl( I first, I last, std::input_iterator_tag ) // basic
   1.313 +        {
   1.314 +            while( first != last )
   1.315 +            {
   1.316 +                insert( end(), null_cloner_type::allocate_clone_from_iterator(first) );
   1.317 +                ++first;
   1.318 +            }
   1.319 +        }
   1.320 +
   1.321 +        template< class I >
   1.322 +        void constructor_impl( I first, I last, std::forward_iterator_tag ) // strong
   1.323 +        {
   1.324 +            if( first == last )
   1.325 +                return;
   1.326 +            clone_back_insert( first, last );
   1.327 +        }
   1.328 +
   1.329 +
   1.330 +    public:
   1.331 +        // overhead: null-initilization of container pointer (very cheap compared to cloning)
   1.332 +        // overhead: 1 heap allocation (very cheap compared to cloning)
   1.333 +        template< class InputIterator >
   1.334 +        reversible_ptr_container( InputIterator first, 
   1.335 +                                  InputIterator last,
   1.336 +                                  const allocator_type& a = allocator_type() ) // basic, strong
   1.337 +        : c_( a )
   1.338 +        { 
   1.339 +            constructor_impl( first, last, 
   1.340 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
   1.341 +#else
   1.342 +                              BOOST_DEDUCED_TYPENAME
   1.343 +#endif                              
   1.344 +                              iterator_category<InputIterator>::type() );
   1.345 +        }
   1.346 +
   1.347 +        template< class Compare >
   1.348 +        reversible_ptr_container( const Compare& comp,
   1.349 +                                  const allocator_type& a )
   1.350 +        : c_( comp, a ) {}
   1.351 +
   1.352 +        template< class PtrContainer, class Compare >
   1.353 +        reversible_ptr_container( std::auto_ptr<PtrContainer> clone, 
   1.354 +                                  Compare comp )
   1.355 +        : c_( comp, allocator_type() )                
   1.356 +        { 
   1.357 +            swap( *clone ); 
   1.358 +        }
   1.359 +
   1.360 +    public:        
   1.361 +        ~reversible_ptr_container()
   1.362 +        { 
   1.363 +            remove_all();
   1.364 +        }
   1.365 +        
   1.366 +        template< class PtrContainer >
   1.367 +        void operator=( std::auto_ptr<PtrContainer> clone )     
   1.368 +        {
   1.369 +            swap( *clone );
   1.370 +        }
   1.371 +
   1.372 +    public:
   1.373 +        
   1.374 +        allocator_type get_allocator() const                   
   1.375 +        {
   1.376 +            return c_.get_allocator(); 
   1.377 +        }
   1.378 + 
   1.379 +    public: // container requirements
   1.380 +        iterator begin()            
   1.381 +            { return iterator( c_.begin() ); }
   1.382 +        const_iterator begin() const      
   1.383 +            { return const_iterator( c_.begin() ); }
   1.384 +        iterator end()              
   1.385 +            { return iterator( c_.end() ); }
   1.386 +        const_iterator end() const        
   1.387 +            { return const_iterator( c_.end() ); }
   1.388 +        
   1.389 +        reverse_iterator rbegin()           
   1.390 +            { return reverse_iterator( this->end() ); } 
   1.391 +        const_reverse_iterator rbegin() const     
   1.392 +            { return const_reverse_iterator( this->end() ); } 
   1.393 +        reverse_iterator rend()             
   1.394 +            { return reverse_iterator( this->begin() ); } 
   1.395 +        const_reverse_iterator rend() const       
   1.396 +            { return const_reverse_iterator( this->begin() ); } 
   1.397 + 
   1.398 +        void swap( reversible_ptr_container& r ) // nothrow
   1.399 +        { 
   1.400 +            c_.swap( r.c_ );
   1.401 +        }
   1.402 +          
   1.403 +        size_type size() const // nothrow
   1.404 +        {
   1.405 +            return c_.size();
   1.406 +        }
   1.407 +
   1.408 +        size_type max_size() const // nothrow
   1.409 +        {
   1.410 +            return c_.max_size(); 
   1.411 +        }
   1.412 +        
   1.413 +        bool empty() const // nothrow
   1.414 +        {
   1.415 +            return c_.empty();
   1.416 +        }
   1.417 +
   1.418 +    public: // optional container requirements
   1.419 +
   1.420 +        bool operator==( const reversible_ptr_container& r ) const // nothrow
   1.421 +        { 
   1.422 +            if( size() != r.size() )
   1.423 +                return false;
   1.424 +            else
   1.425 +                return std::equal( begin(), end(), r.begin() );
   1.426 +        }
   1.427 +
   1.428 +        bool operator!=( const reversible_ptr_container& r ) const // nothrow
   1.429 +        {
   1.430 +            return !(*this == r);
   1.431 +        }
   1.432 +        
   1.433 +        bool operator<( const reversible_ptr_container& r ) const // nothrow 
   1.434 +        {
   1.435 +             return std::lexicographical_compare( begin(), end(), r.begin(), r.end() );
   1.436 +        }
   1.437 +
   1.438 +        bool operator<=( const reversible_ptr_container& r ) const // nothrow 
   1.439 +        {
   1.440 +            return !(r < *this);
   1.441 +        }
   1.442 +
   1.443 +        bool operator>( const reversible_ptr_container& r ) const // nothrow 
   1.444 +        {
   1.445 +            return r < *this;
   1.446 +        }
   1.447 +
   1.448 +        bool operator>=( const reversible_ptr_container& r ) const // nothrow 
   1.449 +        {
   1.450 +            return !(*this < r);
   1.451 +        }
   1.452 +
   1.453 +    public: // modifiers
   1.454 +
   1.455 +        iterator insert( iterator before, Ty_* x )
   1.456 +        {
   1.457 +            enforce_null_policy( x, "Null pointer in 'insert()'" );
   1.458 +
   1.459 +            auto_type ptr( x );                            // nothrow
   1.460 +            iterator res( c_.insert( before.base(), x ) ); // strong, commit
   1.461 +            ptr.release();                                 // nothrow
   1.462 +            return res;
   1.463 +        }
   1.464 +
   1.465 +        template< class U >
   1.466 +        iterator insert( iterator before, std::auto_ptr<U> x )
   1.467 +        {
   1.468 +            return insert( before, x.release() );
   1.469 +        }
   1.470 +
   1.471 +        iterator erase( iterator x ) // nothrow
   1.472 +        {
   1.473 +            BOOST_ASSERT( !empty() );
   1.474 +            BOOST_ASSERT( x != end() );
   1.475 +
   1.476 +            remove( x );
   1.477 +            return iterator( c_.erase( x.base() ) );
   1.478 +        }
   1.479 +
   1.480 +        iterator erase( iterator first, iterator last ) // nothrow
   1.481 +        {
   1.482 +            //BOOST_ASSERT( !empty() );
   1.483 +            remove( first, last );
   1.484 +            return iterator( c_.erase( first.base(),
   1.485 +                                       last.base() ) );
   1.486 +        }
   1.487 +
   1.488 +        template< class Range >
   1.489 +        iterator erase( const Range& r )
   1.490 +        {
   1.491 +            return erase( boost::begin(r), boost::end(r) );
   1.492 +        }
   1.493 +
   1.494 +        void clear()
   1.495 +        {
   1.496 +            remove_all();
   1.497 +            c_.clear();
   1.498 +        }
   1.499 +        
   1.500 +    public: // access interface
   1.501 +        
   1.502 +        auto_type release( iterator where )
   1.503 +        { 
   1.504 +            BOOST_ASSERT( where != end() );
   1.505 +            
   1.506 +            BOOST_PTR_CONTAINER_THROW_EXCEPTION( empty(), bad_ptr_container_operation,
   1.507 +                                                 "'release()' on empty container" ); 
   1.508 +            
   1.509 +            auto_type ptr( Config::get_pointer( where ) );  // nothrow
   1.510 +            c_.erase( where.base() );                       // nothrow
   1.511 +            return boost::ptr_container_detail::move( ptr ); 
   1.512 +        }
   1.513 +
   1.514 +        auto_type replace( iterator where, Ty_* x ) // strong  
   1.515 +        { 
   1.516 +            BOOST_ASSERT( where != end() );
   1.517 +
   1.518 +            enforce_null_policy( x, "Null pointer in 'replace()'" );
   1.519 +            
   1.520 +            auto_type ptr( x );
   1.521 +            
   1.522 +            BOOST_PTR_CONTAINER_THROW_EXCEPTION( empty(), bad_ptr_container_operation,
   1.523 +                                                 "'replace()' on empty container" );
   1.524 +
   1.525 +            auto_type old( Config::get_pointer( where ) );  // nothrow
   1.526 +            
   1.527 +//#if defined( __GNUC__ ) || defined( __MWERKS__ ) || defined( __COMO__ )
   1.528 +            const_cast<void*&>(*where.base()) = ptr.release();                
   1.529 +//#else
   1.530 +//            *where.base() = ptr.release(); // nothrow, commit
   1.531 +//#endif            
   1.532 +            return boost::ptr_container_detail::move( old );
   1.533 +        }
   1.534 +
   1.535 +        template< class U >
   1.536 +        auto_type replace( iterator where, std::auto_ptr<U> x )
   1.537 +        {
   1.538 +            return replace( where, x.release() ); 
   1.539 +        }
   1.540 +
   1.541 +        auto_type replace( size_type idx, Ty_* x ) // strong
   1.542 +        {
   1.543 +            enforce_null_policy( x, "Null pointer in 'replace()'" );
   1.544 +            
   1.545 +            auto_type ptr( x ); 
   1.546 +            
   1.547 +            BOOST_PTR_CONTAINER_THROW_EXCEPTION( idx >= size(), bad_index, 
   1.548 +                                                 "'replace()' out of bounds" );
   1.549 +            
   1.550 +            auto_type old( static_cast<Ty_*>( c_[idx] ) ); // nothrow
   1.551 +            c_[idx] = ptr.release();                       // nothrow, commit
   1.552 +            return boost::ptr_container_detail::move( old );
   1.553 +        } 
   1.554 +
   1.555 +        template< class U >
   1.556 +        auto_type replace( size_type idx, std::auto_ptr<U> x )
   1.557 +        {
   1.558 +            return replace( idx, x.release() );
   1.559 +        }
   1.560 +
   1.561 +    //
   1.562 +    // serialization
   1.563 +    //
   1.564 +    
   1.565 +    protected:
   1.566 +
   1.567 +        template< class Archive >
   1.568 +        void save_helper( Archive& ar ) const
   1.569 +        {
   1.570 +            const_iterator i = this->begin(), e = this->end();
   1.571 +            for( ; i != e; ++i )
   1.572 +                ar & ptr_container_detail::serialize_as_const( 
   1.573 +                                 static_cast<value_type>( *i.base() ) );
   1.574 +        }
   1.575 +
   1.576 +    public: 
   1.577 +
   1.578 +        template< class Archive >
   1.579 +        void save( Archive& ar, const unsigned ) const
   1.580 +        {
   1.581 +            ar & ptr_container_detail::serialize_as_const( this->size() );
   1.582 +            this->save_helper( ar );
   1.583 +        }
   1.584 +
   1.585 +    protected:
   1.586 +
   1.587 +        template< class Archive >
   1.588 +        void load_helper( Archive& ar, size_type n )
   1.589 +        {   
   1.590 +            //
   1.591 +            // Called after an appropriate reserve on c.
   1.592 +            //
   1.593 +
   1.594 +            this->clear();            
   1.595 +            for( size_type i = 0u; i != n; ++i )
   1.596 +            {
   1.597 +                //
   1.598 +                // Remark: pointers are not tracked,
   1.599 +                // so we need not call ar.reset_object_address(v, u)
   1.600 +                //
   1.601 +                value_type ptr;
   1.602 +                ar & ptr;
   1.603 +                this->insert( this->end(), ptr );
   1.604 +            }
   1.605 +        }
   1.606 +
   1.607 +    public:
   1.608 +        
   1.609 +        template< class Archive >
   1.610 +        void load( Archive& ar, const unsigned ) 
   1.611 +        {
   1.612 +            size_type n;
   1.613 +            ar & n;
   1.614 +            this->load_helper( ar, n ); 
   1.615 +        }
   1.616 +        
   1.617 +        BOOST_SERIALIZATION_SPLIT_MEMBER()
   1.618 +        
   1.619 +    }; // 'reversible_ptr_container'
   1.620 +
   1.621 +
   1.622 +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))    
   1.623 +#define BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \
   1.624 +    typename base_type::auto_type                   \
   1.625 +    release( typename base_type::iterator i )       \
   1.626 +    {                                               \
   1.627 +        return boost::ptr_container_detail::move(base_type::release(i)); \
   1.628 +    }                                               
   1.629 +#else
   1.630 +#define BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \
   1.631 +    using base_type::release;
   1.632 +#endif
   1.633 +    
   1.634 +    //
   1.635 +    // two-phase lookup of template functions 
   1.636 +    // is buggy on most compilers, so we use a macro instead
   1.637 +    //
   1.638 +#define BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( PC, base_type, this_type ) \
   1.639 +                                                    \
   1.640 +    PC( std::auto_ptr<this_type> r )                \
   1.641 +    : base_type ( r ) { }                           \
   1.642 +                                                    \
   1.643 +    void operator=( std::auto_ptr<this_type> r )    \
   1.644 +    {                                               \
   1.645 +        base_type::operator=( r );                  \
   1.646 +    }                                               \
   1.647 +                                                    \
   1.648 +    std::auto_ptr<this_type> release()              \
   1.649 +    {                                               \
   1.650 +      std::auto_ptr<this_type> ptr( new this_type );\
   1.651 +      this->swap( *ptr );                           \
   1.652 +      return ptr;                                   \
   1.653 +    }                                               \
   1.654 +    BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \
   1.655 +                                                    \
   1.656 +    std::auto_ptr<this_type> clone() const          \
   1.657 +    {                                               \
   1.658 +       return std::auto_ptr<this_type>( new this_type( this->begin(), this->end() ) ); \
   1.659 +    }
   1.660 +
   1.661 +#define BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( PC, base_type )                       \
   1.662 +    typedef BOOST_DEDUCED_TYPENAME base_type::iterator        iterator;                \
   1.663 +    typedef BOOST_DEDUCED_TYPENAME base_type::size_type       size_type;               \
   1.664 +    typedef BOOST_DEDUCED_TYPENAME base_type::const_reference const_reference;         \
   1.665 +    typedef BOOST_DEDUCED_TYPENAME base_type::allocator_type  allocator_type;          \
   1.666 +    PC( const allocator_type& a = allocator_type() ) : base_type(a) {}                 \
   1.667 +    template< class InputIterator >                                                    \
   1.668 +    PC( InputIterator first, InputIterator last,                                       \
   1.669 +    const allocator_type& a = allocator_type() ) : base_type( first, last, a ) {}      
   1.670 +    
   1.671 +
   1.672 +                 
   1.673 +#define BOOST_PTR_CONTAINER_DEFINE_NON_INHERITED_MEMBERS( PC, base_type, this_type )           \
   1.674 +   BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( PC, base_type )                                    \
   1.675 +   BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( PC, base_type, this_type )
   1.676 +    
   1.677 +    } // namespace 'ptr_container_detail'
   1.678 +
   1.679 +} // namespace 'boost'  
   1.680 +
   1.681 +#endif