File indexing completed on 2025-01-18 09:50:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_PTR_CONTAINER_DETAIL_REVERSIBLE_PTR_CONTAINER_HPP
0014 #define BOOST_PTR_CONTAINER_DETAIL_REVERSIBLE_PTR_CONTAINER_HPP
0015
0016 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 # pragma once
0018 #endif
0019
0020 #include <boost/ptr_container/detail/throw_exception.hpp>
0021 #include <boost/ptr_container/detail/scoped_deleter.hpp>
0022 #include <boost/ptr_container/detail/static_move_ptr.hpp>
0023 #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
0024 #include <boost/ptr_container/exception.hpp>
0025 #include <boost/ptr_container/clone_allocator.hpp>
0026 #include <boost/ptr_container/nullable.hpp>
0027
0028 #ifdef BOOST_NO_SFINAE
0029 #else
0030 #include <boost/range/functions.hpp>
0031 #endif
0032
0033 #include <boost/config.hpp>
0034 #include <boost/iterator/reverse_iterator.hpp>
0035 #include <boost/range/iterator.hpp>
0036 #include <boost/utility/enable_if.hpp>
0037 #include <boost/type_traits/is_pointer.hpp>
0038 #include <boost/type_traits/is_integral.hpp>
0039 #include <boost/core/invoke_swap.hpp>
0040 #include <typeinfo>
0041 #include <memory>
0042
0043 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0044 #pragma warning(push)
0045 #pragma warning(disable:4127)
0046 #pragma warning(disable:4224)
0047 #endif
0048
0049 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
0050 #pragma GCC diagnostic push
0051 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
0052 #endif
0053
0054 namespace boost
0055 {
0056
0057 namespace ptr_container_detail
0058 {
0059 template< class Container >
0060 struct dynamic_clone_deleter
0061 {
0062 dynamic_clone_deleter() { }
0063 dynamic_clone_deleter( Container& cont ) : cont(&cont) { }
0064 Container* cont;
0065
0066 template< class T >
0067 void operator()( const T* p ) const
0068 {
0069
0070 cont->get_clone_allocator().deallocate_clone( p );
0071 }
0072 };
0073
0074 template< class CloneAllocator >
0075 struct static_clone_deleter
0076 {
0077 static_clone_deleter() { }
0078 template< class Dummy >
0079 static_clone_deleter( const Dummy& ) { }
0080
0081 template< class T >
0082 void operator()( const T* p ) const
0083 {
0084
0085 CloneAllocator::deallocate_clone( p );
0086 }
0087 };
0088
0089 template< class T >
0090 struct is_pointer_or_integral
0091 {
0092 BOOST_STATIC_CONSTANT(bool, value = is_pointer<T>::value || is_integral<T>::value );
0093 };
0094
0095 struct is_pointer_or_integral_tag {};
0096 struct is_range_tag {};
0097 struct sequence_tag {};
0098 struct fixed_length_sequence_tag : sequence_tag {};
0099 struct associative_container_tag {};
0100 struct ordered_associative_container_tag : associative_container_tag {};
0101 struct unordered_associative_container_tag : associative_container_tag {};
0102
0103
0104
0105 template
0106 <
0107 class Config,
0108 class CloneAllocator
0109 >
0110 class reversible_ptr_container : CloneAllocator
0111 {
0112 private:
0113 BOOST_STATIC_CONSTANT( bool, allow_null = Config::allow_null );
0114 BOOST_STATIC_CONSTANT( bool, is_clone_allocator_empty = sizeof(CloneAllocator) < sizeof(void*) );
0115
0116 typedef BOOST_DEDUCED_TYPENAME Config::value_type Ty_;
0117 typedef BOOST_DEDUCED_TYPENAME Config::void_container_type container_type;
0118 typedef dynamic_clone_deleter<reversible_ptr_container> dynamic_deleter_type;
0119 typedef static_clone_deleter<CloneAllocator> static_deleter_type;
0120
0121 container_type c_;
0122
0123 public:
0124 container_type& base() { return c_; }
0125 protected:
0126 const container_type& base() const { return c_; }
0127
0128 public:
0129 typedef Ty_ object_type;
0130 typedef Ty_* value_type;
0131 typedef Ty_* pointer;
0132 typedef Ty_& reference;
0133 typedef const Ty_& const_reference;
0134
0135 typedef BOOST_DEDUCED_TYPENAME Config::iterator
0136 iterator;
0137 typedef BOOST_DEDUCED_TYPENAME Config::const_iterator
0138 const_iterator;
0139 typedef boost::reverse_iterator< iterator >
0140 reverse_iterator;
0141 typedef boost::reverse_iterator< const_iterator >
0142 const_reverse_iterator;
0143 typedef BOOST_DEDUCED_TYPENAME container_type::difference_type
0144 difference_type;
0145 typedef BOOST_DEDUCED_TYPENAME container_type::size_type
0146 size_type;
0147 typedef BOOST_DEDUCED_TYPENAME Config::allocator_type
0148 allocator_type;
0149 typedef CloneAllocator clone_allocator_type;
0150 typedef ptr_container_detail::static_move_ptr<Ty_,
0151 BOOST_DEDUCED_TYPENAME boost::mpl::if_c<is_clone_allocator_empty,
0152 static_deleter_type,
0153 dynamic_deleter_type>::type
0154 >
0155 auto_type;
0156
0157 protected:
0158
0159 typedef ptr_container_detail::scoped_deleter<reversible_ptr_container>
0160 scoped_deleter;
0161 typedef BOOST_DEDUCED_TYPENAME container_type::iterator
0162 ptr_iterator;
0163 typedef BOOST_DEDUCED_TYPENAME container_type::const_iterator
0164 ptr_const_iterator;
0165 private:
0166
0167 template< class InputIterator >
0168 void copy( InputIterator first, InputIterator last )
0169 {
0170 std::copy( first, last, begin() );
0171 }
0172
0173 void copy( const reversible_ptr_container& r )
0174 {
0175 this->copy( r.begin(), r.end() );
0176 }
0177
0178 void copy_clones_and_release( scoped_deleter& sd )
0179 {
0180 BOOST_ASSERT( size_type( std::distance( sd.begin(), sd.end() ) ) == c_.size() );
0181 std::copy( sd.begin(), sd.end(), c_.begin() );
0182 sd.release();
0183 }
0184
0185 template< class ForwardIterator >
0186 void clone_assign( ForwardIterator first,
0187 ForwardIterator last )
0188 {
0189 BOOST_ASSERT( first != last );
0190 scoped_deleter sd( *this, first, last );
0191 copy_clones_and_release( sd );
0192 }
0193
0194 template< class ForwardIterator >
0195 void clone_back_insert( ForwardIterator first,
0196 ForwardIterator last )
0197 {
0198 BOOST_ASSERT( first != last );
0199 scoped_deleter sd( *this, first, last );
0200 insert_clones_and_release( sd, end() );
0201 }
0202
0203 void remove_all()
0204 {
0205 this->remove( begin(), end() );
0206 }
0207
0208 protected:
0209
0210 void insert_clones_and_release( scoped_deleter& sd,
0211 iterator where )
0212 {
0213
0214
0215
0216
0217 c_.insert( where.base(),
0218 sd.begin(), sd.end() );
0219 sd.release();
0220 }
0221
0222 void insert_clones_and_release( scoped_deleter& sd )
0223 {
0224 c_.insert( sd.begin(), sd.end() );
0225 sd.release();
0226 }
0227
0228 template< class U >
0229 void remove( U* ptr )
0230 {
0231 this->deallocate_clone( ptr );
0232 }
0233
0234 template< class I >
0235 void remove( I i )
0236 {
0237 this->deallocate_clone( Config::get_const_pointer(i) );
0238 }
0239
0240 template< class I >
0241 void remove( I first, I last )
0242 {
0243 for( ; first != last; ++first )
0244 this->remove( first );
0245 }
0246
0247 static void enforce_null_policy( const Ty_* x, const char* msg )
0248 {
0249 if( !allow_null )
0250 {
0251 BOOST_PTR_CONTAINER_THROW_EXCEPTION( 0 == x && "null not allowed",
0252 bad_pointer, msg );
0253 }
0254 }
0255
0256 public:
0257 Ty_* null_policy_allocate_clone( const Ty_* x )
0258 {
0259 if( allow_null )
0260 {
0261 if( x == 0 )
0262 return 0;
0263 }
0264 else
0265 {
0266 BOOST_ASSERT( x != 0 && "Cannot insert clone of null!" );
0267 }
0268
0269 Ty_* res = this->get_clone_allocator().allocate_clone( *x );
0270 BOOST_ASSERT( typeid(*res) == typeid(*x) &&
0271 "CloneAllocator::allocate_clone() does not clone the "
0272 "object properly. Check that new_clone() is implemented"
0273 " correctly" );
0274 return res;
0275 }
0276
0277 template< class Iterator >
0278 Ty_* null_policy_allocate_clone_from_iterator( Iterator i )
0279 {
0280 return this->null_policy_allocate_clone(Config::get_const_pointer(i));
0281 }
0282
0283 void null_policy_deallocate_clone( const Ty_* x )
0284 {
0285 if( allow_null )
0286 {
0287 if( x == 0 )
0288 return;
0289 }
0290
0291 this->get_clone_allocator().deallocate_clone( x );
0292 }
0293
0294 private:
0295 template< class ForwardIterator >
0296 ForwardIterator advance( ForwardIterator begin, size_type n )
0297 {
0298 ForwardIterator iter = begin;
0299 std::advance( iter, n );
0300 return iter;
0301 }
0302
0303 template< class I >
0304 void constructor_impl( I first, I last, std::input_iterator_tag )
0305 {
0306 while( first != last )
0307 {
0308 insert( end(), this->allocate_clone_from_iterator(first) );
0309 ++first;
0310 }
0311 }
0312
0313 template< class I >
0314 void constructor_impl( I first, I last, std::forward_iterator_tag )
0315 {
0316 if( first == last )
0317 return;
0318 clone_back_insert( first, last );
0319 }
0320
0321 template< class I >
0322 void associative_constructor_impl( I first, I last )
0323 {
0324 if( first == last )
0325 return;
0326
0327 scoped_deleter sd( *this, first, last );
0328 insert_clones_and_release( sd );
0329 }
0330
0331 public:
0332 reversible_ptr_container()
0333 { }
0334
0335 template< class SizeType >
0336 reversible_ptr_container( SizeType n, unordered_associative_container_tag )
0337 : c_( n )
0338 { }
0339
0340 template< class SizeType >
0341 reversible_ptr_container( SizeType n, fixed_length_sequence_tag )
0342 : c_( n )
0343 { }
0344
0345 template< class SizeType >
0346 reversible_ptr_container( SizeType n, const allocator_type& a,
0347 fixed_length_sequence_tag )
0348 : c_( n, a )
0349 { }
0350
0351 explicit reversible_ptr_container( const allocator_type& a )
0352 : c_( a )
0353 { }
0354
0355 #ifndef BOOST_NO_AUTO_PTR
0356 template< class PtrContainer >
0357 explicit reversible_ptr_container( std::auto_ptr<PtrContainer> clone )
0358 {
0359 swap( *clone );
0360 }
0361 #endif
0362 #ifndef BOOST_NO_CXX11_SMART_PTR
0363 template< class PtrContainer >
0364 explicit reversible_ptr_container( std::unique_ptr<PtrContainer> clone )
0365 {
0366 swap( *clone );
0367 }
0368 #endif
0369
0370 reversible_ptr_container( const reversible_ptr_container& r )
0371 {
0372 constructor_impl( r.begin(), r.end(), std::forward_iterator_tag() );
0373 }
0374
0375 template< class C, class V >
0376 reversible_ptr_container( const reversible_ptr_container<C,V>& r )
0377 {
0378 constructor_impl( r.begin(), r.end(), std::forward_iterator_tag() );
0379 }
0380
0381 #ifndef BOOST_NO_AUTO_PTR
0382 template< class PtrContainer >
0383 reversible_ptr_container& operator=( std::auto_ptr<PtrContainer> clone )
0384 {
0385 swap( *clone );
0386 return *this;
0387 }
0388 #endif
0389 #ifndef BOOST_NO_CXX11_SMART_PTR
0390 template< class PtrContainer >
0391 reversible_ptr_container& operator=( std::unique_ptr<PtrContainer> clone )
0392 {
0393 swap( *clone );
0394 return *this;
0395 }
0396 #endif
0397
0398 reversible_ptr_container& operator=( reversible_ptr_container r )
0399 {
0400 swap( r );
0401 return *this;
0402 }
0403
0404
0405
0406 template< class InputIterator >
0407 reversible_ptr_container( InputIterator first,
0408 InputIterator last,
0409 const allocator_type& a = allocator_type() )
0410 : c_( a )
0411 {
0412 constructor_impl( first, last,
0413 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0414 #else
0415 BOOST_DEDUCED_TYPENAME
0416 #endif
0417 iterator_category<InputIterator>::type() );
0418 }
0419
0420 template< class Compare >
0421 reversible_ptr_container( const Compare& comp,
0422 const allocator_type& a )
0423 : c_( comp, a ) {}
0424
0425 template< class ForwardIterator >
0426 reversible_ptr_container( ForwardIterator first,
0427 ForwardIterator last,
0428 fixed_length_sequence_tag )
0429 : c_( std::distance(first,last) )
0430 {
0431 constructor_impl( first, last,
0432 std::forward_iterator_tag() );
0433 }
0434
0435 template< class SizeType, class InputIterator >
0436 reversible_ptr_container( SizeType n,
0437 InputIterator first,
0438 InputIterator last,
0439 fixed_length_sequence_tag )
0440 : c_( n )
0441 {
0442 constructor_impl( first, last,
0443 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0444 #else
0445 BOOST_DEDUCED_TYPENAME
0446 #endif
0447 iterator_category<InputIterator>::type() );
0448 }
0449
0450 template< class Compare >
0451 reversible_ptr_container( const Compare& comp,
0452 const allocator_type& a,
0453 associative_container_tag )
0454 : c_( comp, a )
0455 { }
0456
0457 template< class InputIterator >
0458 reversible_ptr_container( InputIterator first,
0459 InputIterator last,
0460 associative_container_tag )
0461 {
0462 associative_constructor_impl( first, last );
0463 }
0464
0465 template< class InputIterator, class Compare >
0466 reversible_ptr_container( InputIterator first,
0467 InputIterator last,
0468 const Compare& comp,
0469 const allocator_type& a,
0470 associative_container_tag )
0471 : c_( comp, a )
0472 {
0473 associative_constructor_impl( first, last );
0474 }
0475
0476 explicit reversible_ptr_container( size_type n )
0477 : c_( n ) {}
0478
0479 template< class Hash, class Pred >
0480 reversible_ptr_container( const Hash& h,
0481 const Pred& pred,
0482 const allocator_type& a )
0483 : c_( h, pred, a ) {}
0484
0485 template< class InputIterator, class Hash, class Pred >
0486 reversible_ptr_container( InputIterator first,
0487 InputIterator last,
0488 const Hash& h,
0489 const Pred& pred,
0490 const allocator_type& a )
0491 : c_( h, pred, a )
0492 {
0493 associative_constructor_impl( first, last );
0494 }
0495
0496 public:
0497 ~reversible_ptr_container()
0498 {
0499 remove_all();
0500 }
0501
0502 public:
0503
0504 allocator_type get_allocator() const
0505 {
0506 return c_.get_allocator();
0507 }
0508
0509 clone_allocator_type& get_clone_allocator()
0510 {
0511 return static_cast<clone_allocator_type&>(*this);
0512 }
0513
0514 const clone_allocator_type& get_clone_allocator() const
0515 {
0516 return static_cast<const clone_allocator_type&>(*this);
0517 }
0518
0519 public:
0520 iterator begin()
0521 { return iterator( c_.begin() ); }
0522 const_iterator begin() const
0523 { return const_iterator( c_.begin() ); }
0524 iterator end()
0525 { return iterator( c_.end() ); }
0526 const_iterator end() const
0527 { return const_iterator( c_.end() ); }
0528
0529 reverse_iterator rbegin()
0530 { return reverse_iterator( this->end() ); }
0531 const_reverse_iterator rbegin() const
0532 { return const_reverse_iterator( this->end() ); }
0533 reverse_iterator rend()
0534 { return reverse_iterator( this->begin() ); }
0535 const_reverse_iterator rend() const
0536 { return const_reverse_iterator( this->begin() ); }
0537
0538 const_iterator cbegin() const
0539 { return const_iterator( c_.begin() ); }
0540 const_iterator cend() const
0541 { return const_iterator( c_.end() ); }
0542
0543 const_reverse_iterator crbegin() const
0544 { return const_reverse_iterator( this->end() ); }
0545 const_reverse_iterator crend() const
0546 { return const_reverse_iterator( this->begin() ); }
0547
0548 void swap( reversible_ptr_container& r )
0549 {
0550 boost::core::invoke_swap( get_clone_allocator(), r.get_clone_allocator() );
0551 c_.swap( r.c_ );
0552 }
0553
0554 size_type size() const
0555 {
0556 return c_.size();
0557 }
0558
0559 size_type max_size() const
0560 {
0561 return c_.max_size();
0562 }
0563
0564 bool empty() const
0565 {
0566 return c_.empty();
0567 }
0568
0569 public:
0570
0571 bool operator==( const reversible_ptr_container& r ) const
0572 {
0573 if( size() != r.size() )
0574 return false;
0575 else
0576 return std::equal( begin(), end(), r.begin() );
0577 }
0578
0579 bool operator!=( const reversible_ptr_container& r ) const
0580 {
0581 return !(*this == r);
0582 }
0583
0584 bool operator<( const reversible_ptr_container& r ) const
0585 {
0586 return std::lexicographical_compare( begin(), end(), r.begin(), r.end() );
0587 }
0588
0589 bool operator<=( const reversible_ptr_container& r ) const
0590 {
0591 return !(r < *this);
0592 }
0593
0594 bool operator>( const reversible_ptr_container& r ) const
0595 {
0596 return r < *this;
0597 }
0598
0599 bool operator>=( const reversible_ptr_container& r ) const
0600 {
0601 return !(*this < r);
0602 }
0603
0604 public:
0605
0606 iterator insert( iterator before, Ty_* x )
0607 {
0608 enforce_null_policy( x, "Null pointer in 'insert()'" );
0609
0610 auto_type ptr( x, *this );
0611 iterator res( c_.insert( before.base(), x ) );
0612 ptr.release();
0613 return res;
0614 }
0615
0616 #ifndef BOOST_NO_AUTO_PTR
0617 template< class U >
0618 iterator insert( iterator before, std::auto_ptr<U> x )
0619 {
0620 return insert( before, x.release() );
0621 }
0622 #endif
0623 #ifndef BOOST_NO_CXX11_SMART_PTR
0624 template< class U >
0625 iterator insert( iterator before, std::unique_ptr<U> x )
0626 {
0627 return insert( before, x.release() );
0628 }
0629 #endif
0630
0631 iterator erase( iterator x )
0632 {
0633 BOOST_ASSERT( !empty() );
0634 BOOST_ASSERT( x != end() );
0635
0636 remove( x );
0637 return iterator( c_.erase( x.base() ) );
0638 }
0639
0640 iterator erase( iterator first, iterator last )
0641 {
0642 remove( first, last );
0643 return iterator( c_.erase( first.base(),
0644 last.base() ) );
0645 }
0646
0647 template< class Range >
0648 iterator erase( const Range& r )
0649 {
0650 return erase( boost::begin(r), boost::end(r) );
0651 }
0652
0653 void clear()
0654 {
0655 remove_all();
0656 c_.clear();
0657 }
0658
0659 public:
0660
0661 auto_type release( iterator where )
0662 {
0663 BOOST_ASSERT( where != end() );
0664
0665 BOOST_PTR_CONTAINER_THROW_EXCEPTION( empty(), bad_ptr_container_operation,
0666 "'release()' on empty container" );
0667
0668 auto_type ptr( Config::get_pointer(where), *this );
0669 c_.erase( where.base() );
0670 return boost::ptr_container_detail::move( ptr );
0671 }
0672
0673 auto_type replace( iterator where, Ty_* x )
0674 {
0675 BOOST_ASSERT( where != end() );
0676 enforce_null_policy( x, "Null pointer in 'replace()'" );
0677
0678 auto_type ptr( x, *this );
0679 BOOST_PTR_CONTAINER_THROW_EXCEPTION( empty(), bad_ptr_container_operation,
0680 "'replace()' on empty container" );
0681
0682 auto_type old( Config::get_pointer(where), *this );
0683 const_cast<void*&>(*where.base()) = ptr.release();
0684 return boost::ptr_container_detail::move( old );
0685 }
0686
0687 #ifndef BOOST_NO_AUTO_PTR
0688 template< class U >
0689 auto_type replace( iterator where, std::auto_ptr<U> x )
0690 {
0691 return replace( where, x.release() );
0692 }
0693 #endif
0694 #ifndef BOOST_NO_CXX11_SMART_PTR
0695 template< class U >
0696 auto_type replace( iterator where, std::unique_ptr<U> x )
0697 {
0698 return replace( where, x.release() );
0699 }
0700 #endif
0701
0702 auto_type replace( size_type idx, Ty_* x )
0703 {
0704 enforce_null_policy( x, "Null pointer in 'replace()'" );
0705
0706 auto_type ptr( x, *this );
0707 BOOST_PTR_CONTAINER_THROW_EXCEPTION( idx >= size(), bad_index,
0708 "'replace()' out of bounds" );
0709
0710 auto_type old( static_cast<Ty_*>(c_[idx]), *this );
0711 c_[idx] = ptr.release();
0712 return boost::ptr_container_detail::move( old );
0713 }
0714
0715 #ifndef BOOST_NO_AUTO_PTR
0716 template< class U >
0717 auto_type replace( size_type idx, std::auto_ptr<U> x )
0718 {
0719 return replace( idx, x.release() );
0720 }
0721 #endif
0722 #ifndef BOOST_NO_CXX11_SMART_PTR
0723 template< class U >
0724 auto_type replace( size_type idx, std::unique_ptr<U> x )
0725 {
0726 return replace( idx, x.release() );
0727 }
0728 #endif
0729
0730 };
0731
0732
0733 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0734 #define BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \
0735 typename base_type::auto_type \
0736 release( typename base_type::iterator i ) \
0737 { \
0738 return boost::ptr_container_detail::move(base_type::release(i)); \
0739 }
0740 #else
0741 #define BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type ) \
0742 using base_type::release;
0743 #endif
0744
0745 #ifndef BOOST_NO_AUTO_PTR
0746 #define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_AUTO( PC, base_type, this_type ) \
0747 explicit PC( std::auto_ptr<this_type> r ) \
0748 : base_type ( r ) { } \
0749 \
0750 PC& operator=( std::auto_ptr<this_type> r ) \
0751 { \
0752 base_type::operator=( r ); \
0753 return *this; \
0754 }
0755 #else
0756 #define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_AUTO( PC, base_type, this_type )
0757 #endif
0758
0759 #ifndef BOOST_NO_CXX11_SMART_PTR
0760 #define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_UNIQUE( PC, base_type, this_type ) \
0761 explicit PC( std::unique_ptr<this_type> r ) \
0762 : base_type ( std::move( r ) ) { } \
0763 \
0764 PC& operator=( std::unique_ptr<this_type> r ) \
0765 { \
0766 base_type::operator=( std::move( r ) ); \
0767 return *this; \
0768 }
0769 #else
0770 #define BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_UNIQUE( PC, base_type, this_type )
0771 #endif
0772
0773 #ifndef BOOST_NO_AUTO_PTR
0774 #define BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) \
0775 std::auto_ptr<this_type> release() \
0776 { \
0777 std::auto_ptr<this_type> ptr( new this_type );\
0778 this->swap( *ptr ); \
0779 return ptr; \
0780 } \
0781 \
0782 std::auto_ptr<this_type> clone() const \
0783 { \
0784 return std::auto_ptr<this_type>( new this_type( this->begin(), this->end() ) ); \
0785 }
0786 #elif !defined( BOOST_NO_CXX11_SMART_PTR )
0787 #define BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) \
0788 std::unique_ptr<this_type> release() \
0789 { \
0790 std::unique_ptr<this_type> ptr( new this_type );\
0791 this->swap( *ptr ); \
0792 return ptr; \
0793 } \
0794 \
0795 std::unique_ptr<this_type> clone() const \
0796 { \
0797 return std::unique_ptr<this_type>( new this_type( this->begin(), this->end() ) ); \
0798 }
0799 #else
0800 #define BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type )
0801 #endif
0802
0803
0804
0805
0806
0807 #define BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( PC, base_type, this_type ) \
0808 BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_AUTO( PC, base_type, this_type ) \
0809 BOOST_PTR_CONTAINER_COPY_AND_ASSIGN_UNIQUE( PC, base_type, this_type ) \
0810 BOOST_PTR_CONTAINER_RELEASE_AND_CLONE( this_type ) \
0811 BOOST_PTR_CONTAINER_DEFINE_RELEASE( base_type )
0812
0813 #define BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( PC, base_type ) \
0814 \
0815 template< class U > \
0816 PC( const PC<U>& r ) : base_type( r ) { } \
0817 \
0818 PC& operator=( PC r ) \
0819 { \
0820 this->swap( r ); \
0821 return *this; \
0822 } \
0823
0824
0825 #define BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( PC, base_type ) \
0826 typedef BOOST_DEDUCED_TYPENAME base_type::iterator iterator; \
0827 typedef BOOST_DEDUCED_TYPENAME base_type::size_type size_type; \
0828 typedef BOOST_DEDUCED_TYPENAME base_type::const_reference const_reference; \
0829 typedef BOOST_DEDUCED_TYPENAME base_type::allocator_type allocator_type; \
0830 PC() {} \
0831 explicit PC( const allocator_type& a ) : base_type(a) {} \
0832 template< class InputIterator > \
0833 PC( InputIterator first, InputIterator last ) : base_type( first, last ) {} \
0834 template< class InputIterator > \
0835 PC( InputIterator first, InputIterator last, \
0836 const allocator_type& a ) : base_type( first, last, a ) {}
0837
0838 #define BOOST_PTR_CONTAINER_DEFINE_NON_INHERITED_MEMBERS( PC, base_type, this_type ) \
0839 BOOST_PTR_CONTAINER_DEFINE_CONSTRUCTORS( PC, base_type ) \
0840 BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( PC, base_type, this_type )
0841
0842 #define BOOST_PTR_CONTAINER_DEFINE_SEQEUENCE_MEMBERS( PC, base_type, this_type ) \
0843 BOOST_PTR_CONTAINER_DEFINE_NON_INHERITED_MEMBERS( PC, base_type, this_type ) \
0844 BOOST_PTR_CONTAINER_DEFINE_COPY_CONSTRUCTORS( PC, base_type )
0845
0846 }
0847
0848
0849
0850
0851 namespace ptr_container
0852 {
0853 using ptr_container_detail::move;
0854 }
0855
0856 }
0857
0858 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
0859 #pragma GCC diagnostic pop
0860 #endif
0861
0862 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0863 #pragma warning(pop)
0864 #endif
0865
0866 #endif