123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982 |
- //
- // Boost.Pointer Container
- //
- // Copyright Thorsten Ottosen 2003-2005. Use, modification and
- // distribution is subject to the Boost Software License, Version
- // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- //
- // For more information, see http://www.boost.org/libs/ptr_container/
- //
- #ifndef BOOST_PTR_CONTAINER_DETAIL_PTR_MAP_ADAPTER_HPP
- #define BOOST_PTR_CONTAINER_DETAIL_PTR_MAP_ADAPTER_HPP
- #if defined(_MSC_VER) && (_MSC_VER >= 1200)
- # pragma once
- #endif
- #include <boost/ptr_container/detail/map_iterator.hpp>
- #include <boost/ptr_container/detail/associative_ptr_container.hpp>
- #include <boost/ptr_container/detail/meta_functions.hpp>
- #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
- #include <boost/static_assert.hpp>
- #include <boost/range/iterator_range.hpp>
- #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
- #pragma GCC diagnostic push
- #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
- #endif
- namespace boost
- {
- namespace ptr_container_detail
- {
- template
- <
- class T,
- class VoidPtrMap,
- bool Ordered
- >
- struct map_config
- {
- typedef BOOST_DEDUCED_TYPENAME remove_nullable<T>::type
- U;
- typedef VoidPtrMap
- void_container_type;
-
- typedef BOOST_DEDUCED_TYPENAME VoidPtrMap::allocator_type
- allocator_type;
-
- typedef BOOST_DEDUCED_TYPENAME
- mpl::eval_if_c<Ordered,
- select_value_compare<VoidPtrMap>,
- mpl::identity<void> >::type
- value_compare;
- typedef BOOST_DEDUCED_TYPENAME
- mpl::eval_if_c<Ordered,
- select_key_compare<VoidPtrMap>,
- mpl::identity<void> >::type
- key_compare;
- typedef BOOST_DEDUCED_TYPENAME
- mpl::eval_if_c<Ordered,
- mpl::identity<void>,
- select_hasher<VoidPtrMap> >::type
- hasher;
- typedef BOOST_DEDUCED_TYPENAME
- mpl::eval_if_c<Ordered,
- mpl::identity<void>,
- select_key_equal<VoidPtrMap> >::type
- key_equal;
- typedef BOOST_DEDUCED_TYPENAME
- mpl::if_c<Ordered,
- ptr_container_detail::ordered_associative_container_tag,
- ptr_container_detail::unordered_associative_container_tag>::type
- container_type;
-
- typedef BOOST_DEDUCED_TYPENAME VoidPtrMap::key_type
- key_type;
-
- typedef U value_type;
- typedef ptr_map_iterator< BOOST_DEDUCED_TYPENAME VoidPtrMap::iterator, key_type, U* const >
- iterator;
-
- typedef ptr_map_iterator< BOOST_DEDUCED_TYPENAME VoidPtrMap::const_iterator, key_type, const U* const>
- const_iterator;
-
- typedef ptr_map_iterator<
- BOOST_DEDUCED_TYPENAME
- mpl::eval_if_c<Ordered,
- select_iterator<VoidPtrMap>,
- select_local_iterator<VoidPtrMap> >::type,
- key_type, U* const >
- local_iterator;
- typedef ptr_map_iterator<
- BOOST_DEDUCED_TYPENAME
- mpl::eval_if_c<Ordered,
- select_iterator<VoidPtrMap>,
- select_const_local_iterator<VoidPtrMap> >::type,
- key_type, const U* const >
- const_local_iterator;
-
- template< class Iter >
- static U* get_pointer( Iter i )
- {
- return i->second;
- }
- template< class Iter >
- static const U* get_const_pointer( Iter i )
- {
- return i->second;
- }
- BOOST_STATIC_CONSTANT( bool, allow_null = boost::is_nullable<T>::value );
- };
-
-
- template
- <
- class T,
- class VoidPtrMap,
- class CloneAllocator,
- bool Ordered
- >
- class ptr_map_adapter_base :
- public ptr_container_detail::associative_ptr_container< map_config<T,VoidPtrMap,Ordered>,
- CloneAllocator >
- {
- typedef ptr_container_detail::associative_ptr_container< map_config<T,VoidPtrMap,Ordered>,
- CloneAllocator >
- base_type;
- typedef map_config<T,VoidPtrMap,Ordered> config;
- typedef ptr_map_adapter_base<T,VoidPtrMap,CloneAllocator,Ordered> this_type;
-
- public:
- typedef BOOST_DEDUCED_TYPENAME base_type::allocator_type
- allocator_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::iterator
- iterator;
- typedef BOOST_DEDUCED_TYPENAME base_type::const_iterator
- const_iterator;
- typedef BOOST_DEDUCED_TYPENAME base_type::size_type
- size_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::key_type
- key_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::auto_type
- auto_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::value_type
- mapped_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::reference
- mapped_reference;
- typedef BOOST_DEDUCED_TYPENAME base_type::const_reference
- const_mapped_reference;
- typedef BOOST_DEDUCED_TYPENAME iterator_value<iterator>::type
- value_type;
- typedef value_type
- reference;
- typedef BOOST_DEDUCED_TYPENAME iterator_value<const_iterator>::type
- const_reference;
- typedef value_type
- pointer;
- typedef const_reference
- const_pointer;
- private:
- const_mapped_reference lookup( const key_type& key ) const
- {
- const_iterator i = this->find( key );
- BOOST_PTR_CONTAINER_THROW_EXCEPTION( i == this->end(), bad_ptr_container_operation,
- "'ptr_map/multimap::at()' could"
- " not find key" );
- return *i->second;
- }
- struct eraser // scope guard
- {
- bool released_;
- VoidPtrMap* m_;
- const key_type& key_;
- eraser( VoidPtrMap* m, const key_type& key )
- : released_(false), m_(m), key_(key)
- {}
- ~eraser()
- {
- if( !released_ )
- m_->erase(key_);
- }
- void release() { released_ = true; }
- private:
- eraser& operator=(const eraser&);
- };
- mapped_reference insert_lookup( const key_type& key )
- {
- void*& ref = this->base()[key];
- if( ref )
- {
- return *static_cast<mapped_type>(ref);
- }
- else
- {
- eraser e(&this->base(),key); // nothrow
- mapped_type res = new T(); // strong
- ref = res; // nothrow
- e.release(); // nothrow
- return *res;
- }
- }
-
- public:
- ptr_map_adapter_base()
- { }
- template< class SizeType >
- explicit ptr_map_adapter_base( SizeType n,
- ptr_container_detail::unordered_associative_container_tag tag )
- : base_type( n, tag )
- { }
- template< class Compare, class Allocator >
- ptr_map_adapter_base( const Compare& comp,
- const Allocator& a )
- : base_type( comp, a )
- { }
- template< class Hash, class Pred, class Allocator >
- ptr_map_adapter_base( const Hash& hash,
- const Pred& pred,
- const Allocator& a )
- : base_type( hash, pred, a )
- { }
-
- template< class InputIterator >
- ptr_map_adapter_base( InputIterator first, InputIterator last )
- : base_type( first, last )
- { }
-
- template< class InputIterator, class Comp >
- ptr_map_adapter_base( InputIterator first, InputIterator last,
- const Comp& comp,
- const allocator_type& a = allocator_type() )
- : base_type( first, last, comp, a )
- { }
- template< class InputIterator, class Hash, class Pred, class Allocator >
- ptr_map_adapter_base( InputIterator first, InputIterator last,
- const Hash& hash,
- const Pred& pred,
- const Allocator& a )
- : base_type( first, last, hash, pred, a )
- { }
-
- #ifndef BOOST_NO_AUTO_PTR
- template< class PtrContainer >
- explicit ptr_map_adapter_base( std::auto_ptr<PtrContainer> clone )
- : base_type( clone )
- { }
- template< typename PtrContainer >
- ptr_map_adapter_base& operator=( std::auto_ptr<PtrContainer> clone )
- {
- base_type::operator=( clone );
- return *this;
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class PtrContainer >
- explicit ptr_map_adapter_base( std::unique_ptr<PtrContainer> clone )
- : base_type( std::move( clone ) )
- { }
- template< typename PtrContainer >
- ptr_map_adapter_base& operator=( std::unique_ptr<PtrContainer> clone )
- {
- base_type::operator=( std::move( clone ) );
- return *this;
- }
- #endif
- iterator find( const key_type& x )
- {
- return iterator( this->base().find( x ) );
- }
- const_iterator find( const key_type& x ) const
- {
- return const_iterator( this->base().find( x ) );
- }
- size_type count( const key_type& x ) const
- {
- return this->base().count( x );
- }
-
- iterator lower_bound( const key_type& x )
- {
- return iterator( this->base().lower_bound( x ) );
- }
-
- const_iterator lower_bound( const key_type& x ) const
- {
- return const_iterator( this->base().lower_bound( x ) );
- }
-
- iterator upper_bound( const key_type& x )
- {
- return iterator( this->base().upper_bound( x ) );
- }
-
- const_iterator upper_bound( const key_type& x ) const
- {
- return const_iterator( this->base().upper_bound( x ) );
- }
-
- iterator_range<iterator> equal_range( const key_type& x )
- {
- std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,
- BOOST_DEDUCED_TYPENAME base_type::ptr_iterator>
- p = this->base().equal_range( x );
- return make_iterator_range( iterator( p.first ), iterator( p.second ) );
- }
-
- iterator_range<const_iterator> equal_range( const key_type& x ) const
- {
- std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator,
- BOOST_DEDUCED_TYPENAME base_type::ptr_const_iterator>
- p = this->base().equal_range( x );
- return make_iterator_range( const_iterator( p.first ),
- const_iterator( p.second ) );
- }
-
- mapped_reference at( const key_type& key )
- {
- return const_cast<mapped_reference>( lookup( key ) );
- }
-
- const_mapped_reference at( const key_type& key ) const
- {
- return lookup( key );
- }
- mapped_reference operator[]( const key_type& key )
- {
- return insert_lookup( key );
- }
- auto_type replace( iterator where, mapped_type x ) // strong
- {
- BOOST_ASSERT( where != this->end() );
- this->enforce_null_policy( x, "Null pointer in 'replace()'" );
- auto_type ptr( x, *this );
- BOOST_PTR_CONTAINER_THROW_EXCEPTION( this->empty(),
- bad_ptr_container_operation,
- "'replace()' on empty container" );
- auto_type old( where->second, *this ); // nothrow
- where.base()->second = ptr.release(); // nothrow, commit
- return boost::ptr_container::move( old );
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- auto_type replace( iterator where, std::auto_ptr<U> x )
- {
- return replace( where, x.release() );
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- auto_type replace( iterator where, std::unique_ptr<U> x )
- {
- return replace( where, x.release() );
- }
- #endif
- protected:
- size_type bucket( const key_type& key ) const
- {
- return this->base().bucket( key );
- }
- };
-
- } // ptr_container_detail
- /////////////////////////////////////////////////////////////////////////
- // ptr_map_adapter
- /////////////////////////////////////////////////////////////////////////
-
- template
- <
- class T,
- class VoidPtrMap,
- class CloneAllocator = heap_clone_allocator,
- bool Ordered = true
- >
- class ptr_map_adapter :
- public ptr_container_detail::ptr_map_adapter_base<T,VoidPtrMap,CloneAllocator,Ordered>
- {
- typedef ptr_container_detail::ptr_map_adapter_base<T,VoidPtrMap,CloneAllocator,Ordered>
- base_type;
-
- public:
- typedef BOOST_DEDUCED_TYPENAME base_type::iterator
- iterator;
- typedef BOOST_DEDUCED_TYPENAME base_type::const_iterator
- const_iterator;
- typedef BOOST_DEDUCED_TYPENAME base_type::size_type
- size_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::key_type
- key_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::const_reference
- const_reference;
- typedef BOOST_DEDUCED_TYPENAME base_type::auto_type
- auto_type;
- typedef BOOST_DEDUCED_TYPENAME VoidPtrMap::allocator_type
- allocator_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::mapped_type
- mapped_type;
- private:
- void safe_insert( const key_type& key, auto_type ptr ) // strong
- {
- std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
- res =
- this->base().insert( std::make_pair( key, ptr.get() ) ); // strong, commit
- if( res.second ) // nothrow
- ptr.release(); // nothrow
- }
- template< class II >
- void map_basic_clone_and_insert( II first, II last )
- {
- while( first != last )
- {
- if( this->find( first->first ) == this->end() )
- {
- const_reference p = *first.base(); // nothrow
- auto_type ptr( this->null_policy_allocate_clone(p.second), *this );
- // strong
- this->safe_insert( p.first,
- boost::ptr_container::move( ptr ) );
- // strong, commit
- }
- ++first;
- }
- }
-
- public:
- ptr_map_adapter( )
- { }
- template< class Comp >
- explicit ptr_map_adapter( const Comp& comp,
- const allocator_type& a )
- : base_type( comp, a ) { }
- template< class SizeType >
- explicit ptr_map_adapter( SizeType n,
- ptr_container_detail::unordered_associative_container_tag tag )
- : base_type( n, tag ) { }
- template< class Hash, class Pred, class Allocator >
- ptr_map_adapter( const Hash& hash,
- const Pred& pred,
- const Allocator& a )
- : base_type( hash, pred, a )
- { }
-
- template< class InputIterator >
- ptr_map_adapter( InputIterator first, InputIterator last )
- {
- map_basic_clone_and_insert( first, last );
- }
-
- template< class InputIterator, class Comp >
- ptr_map_adapter( InputIterator first, InputIterator last,
- const Comp& comp,
- const allocator_type& a = allocator_type() )
- : base_type( comp, a )
- {
- map_basic_clone_and_insert( first, last );
- }
- template< class InputIterator, class Hash, class Pred, class Allocator >
- ptr_map_adapter( InputIterator first, InputIterator last,
- const Hash& hash,
- const Pred& pred,
- const Allocator& a )
- : base_type( hash, pred, a )
- {
- map_basic_clone_and_insert( first, last );
- }
-
- ptr_map_adapter( const ptr_map_adapter& r )
- {
- map_basic_clone_and_insert( r.begin(), r.end() );
- }
-
- template< class Key, class U, class CA, bool b >
- ptr_map_adapter( const ptr_map_adapter<Key,U,CA,b>& r )
- {
- map_basic_clone_and_insert( r.begin(), r.end() );
- }
-
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- ptr_map_adapter( std::auto_ptr<U> r ) : base_type( r )
- { }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- ptr_map_adapter( std::unique_ptr<U> r ) : base_type( std::move( r ) )
- { }
- #endif
- ptr_map_adapter& operator=( ptr_map_adapter r )
- {
- this->swap( r );
- return *this;
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- ptr_map_adapter& operator=( std::auto_ptr<U> r )
- {
- base_type::operator=( r );
- return *this;
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- ptr_map_adapter& operator=( std::unique_ptr<U> r )
- {
- base_type::operator=( std::move( r ) );
- return *this;
- }
- #endif
- using base_type::release;
- template< typename InputIterator >
- void insert( InputIterator first, InputIterator last ) // basic
- {
- map_basic_clone_and_insert( first, last );
- }
- template< class Range >
- void insert( const Range& r )
- {
- insert( boost::begin(r), boost::end(r) );
- }
- private:
- std::pair<iterator,bool> insert_impl( const key_type& key, mapped_type x ) // strong
- {
- this->enforce_null_policy( x, "Null pointer in ptr_map_adapter::insert()" );
- auto_type ptr( x, *this ); // nothrow
- std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
- res = this->base().insert( std::make_pair( key, x ) ); // strong, commit
- if( res.second ) // nothrow
- ptr.release(); // nothrow
- return std::make_pair( iterator( res.first ), res.second ); // nothrow
- }
- iterator insert_impl( iterator before, const key_type& key, mapped_type x ) // strong
- {
- this->enforce_null_policy( x,
- "Null pointer in 'ptr_map_adapter::insert()'" );
-
- auto_type ptr( x, *this ); // nothrow
- BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
- res = this->base().insert( before.base(), std::make_pair( key, x ) );
- // strong, commit
- ptr.release(); // notrow
- return iterator( res );
- }
-
- public:
-
- std::pair<iterator,bool> insert( key_type& key, mapped_type x )
- {
- return insert_impl( key, x );
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- std::pair<iterator,bool> insert( const key_type& key, std::auto_ptr<U> x )
- {
- return insert_impl( key, x.release() );
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- std::pair<iterator,bool> insert( const key_type& key, std::unique_ptr<U> x )
- {
- return insert_impl( key, x.release() );
- }
- #endif
- template< class F, class S >
- iterator insert( iterator before, ptr_container_detail::ref_pair<F,S> p ) // strong
- {
- this->enforce_null_policy( p.second,
- "Null pointer in 'ptr_map_adapter::insert()'" );
-
- auto_type ptr( this->null_policy_allocate_clone(p.second), *this );
- BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
- result = this->base().insert( before.base(),
- std::make_pair(p.first,ptr.get()) ); // strong
- if( ptr.get() == result->second )
- ptr.release();
-
- return iterator( result );
- }
- iterator insert( iterator before, key_type& key, mapped_type x ) // strong
- {
- return insert_impl( before, key, x );
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- iterator insert( iterator before, const key_type& key, std::auto_ptr<U> x ) // strong
- {
- return insert_impl( before, key, x.release() );
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- iterator insert( iterator before, const key_type& key, std::unique_ptr<U> x ) // strong
- {
- return insert_impl( before, key, x.release() );
- }
- #endif
-
- template< class PtrMapAdapter >
- bool transfer( BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator object,
- PtrMapAdapter& from ) // strong
- {
- return this->single_transfer( object, from );
- }
- template< class PtrMapAdapter >
- size_type transfer( BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator first,
- BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator last,
- PtrMapAdapter& from ) // basic
- {
- return this->single_transfer( first, last, from );
- }
- #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
- #else
- template< class PtrMapAdapter, class Range >
- BOOST_DEDUCED_TYPENAME boost::disable_if< boost::is_same< Range,
- BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator >,
- size_type >::type
- transfer( const Range& r, PtrMapAdapter& from ) // basic
- {
- return transfer( boost::begin(r), boost::end(r), from );
- }
-
- #endif
- template< class PtrMapAdapter >
- size_type transfer( PtrMapAdapter& from ) // basic
- {
- return transfer( from.begin(), from.end(), from );
- }
- };
-
- /////////////////////////////////////////////////////////////////////////
- // ptr_multimap_adapter
- /////////////////////////////////////////////////////////////////////////
- template
- <
- class T,
- class VoidPtrMultiMap,
- class CloneAllocator = heap_clone_allocator,
- bool Ordered = true
- >
- class ptr_multimap_adapter :
- public ptr_container_detail::ptr_map_adapter_base<T,VoidPtrMultiMap,CloneAllocator,Ordered>
- {
- typedef ptr_container_detail::ptr_map_adapter_base<T,VoidPtrMultiMap,CloneAllocator,Ordered>
- base_type;
- public: // typedefs
- typedef BOOST_DEDUCED_TYPENAME base_type::iterator
- iterator;
- typedef BOOST_DEDUCED_TYPENAME base_type::const_iterator
- const_iterator;
- typedef BOOST_DEDUCED_TYPENAME base_type::size_type
- size_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::key_type
- key_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::const_reference
- const_reference;
- typedef BOOST_DEDUCED_TYPENAME base_type::mapped_type
- mapped_type;
- typedef BOOST_DEDUCED_TYPENAME base_type::auto_type
- auto_type;
- typedef BOOST_DEDUCED_TYPENAME VoidPtrMultiMap::allocator_type
- allocator_type;
- private:
- void safe_insert( const key_type& key, auto_type ptr ) // strong
- {
- this->base().insert(
- std::make_pair( key, ptr.get() ) ); // strong, commit
- ptr.release(); // nothrow
- }
-
- template< typename II >
- void map_basic_clone_and_insert( II first, II last )
- {
- while( first != last )
- {
- const_reference pair = *first.base(); // nothrow
- auto_type ptr( this->null_policy_allocate_clone(pair.second), *this );
- // strong
- safe_insert( pair.first,
- boost::ptr_container::move( ptr ) );
- // strong, commit
- ++first;
- }
- }
-
- public:
- ptr_multimap_adapter()
- { }
- template< class SizeType >
- ptr_multimap_adapter( SizeType n,
- ptr_container_detail::unordered_associative_container_tag tag )
- : base_type( n, tag )
- { }
- template< class Comp >
- explicit ptr_multimap_adapter( const Comp& comp,
- const allocator_type& a )
- : base_type( comp, a ) { }
- template< class Hash, class Pred, class Allocator >
- ptr_multimap_adapter( const Hash& hash,
- const Pred& pred,
- const Allocator& a )
- : base_type( hash, pred, a )
- { }
- template< class InputIterator >
- ptr_multimap_adapter( InputIterator first, InputIterator last )
- {
- map_basic_clone_and_insert( first, last );
- }
-
- template< class InputIterator, class Comp >
- ptr_multimap_adapter( InputIterator first, InputIterator last,
- const Comp& comp,
- const allocator_type& a )
- : base_type( comp, a )
- {
- map_basic_clone_and_insert( first, last );
- }
- template< class InputIterator, class Hash, class Pred, class Allocator >
- ptr_multimap_adapter( InputIterator first, InputIterator last,
- const Hash& hash,
- const Pred& pred,
- const Allocator& a )
- : base_type( hash, pred, a )
- {
- map_basic_clone_and_insert( first, last );
- }
- ptr_multimap_adapter( const ptr_multimap_adapter& r )
- {
- map_basic_clone_and_insert( r.begin(), r.end() );
- }
-
- template< class Key, class U, class CA, bool b >
- ptr_multimap_adapter( const ptr_multimap_adapter<Key,U,CA,b>& r )
- {
- map_basic_clone_and_insert( r.begin(), r.end() );
- }
-
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- explicit ptr_multimap_adapter( std::auto_ptr<U> r ) : base_type( r )
- { }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- explicit ptr_multimap_adapter( std::unique_ptr<U> r ) : base_type( std::move( r ) )
- { }
- #endif
- ptr_multimap_adapter& operator=( ptr_multimap_adapter r )
- {
- this->swap( r );
- return *this;
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- ptr_multimap_adapter& operator=( std::auto_ptr<U> r )
- {
- base_type::operator=( r );
- return *this;
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- ptr_multimap_adapter& operator=( std::unique_ptr<U> r )
- {
- base_type::operator=( std::move( r ) );
- return *this;
- }
- #endif
- using base_type::release;
- private:
- iterator insert_impl( const key_type& key, mapped_type x ) // strong
- {
- this->enforce_null_policy( x,
- "Null pointer in 'ptr_multimap_adapter::insert()'" );
- auto_type ptr( x, *this ); // nothrow
- BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
- res = this->base().insert( std::make_pair( key, x ) );
- // strong, commit
- ptr.release(); // notrow
- return iterator( res );
- }
- iterator insert_impl( iterator before, const key_type& key, mapped_type x ) // strong
- {
- this->enforce_null_policy( x,
- "Null pointer in 'ptr_multimap_adapter::insert()'" );
-
- auto_type ptr( x, *this ); // nothrow
- BOOST_DEDUCED_TYPENAME base_type::ptr_iterator
- res = this->base().insert( before.base(),
- std::make_pair( key, x ) );
- // strong, commit
- ptr.release(); // notrow
- return iterator( res );
- }
- public:
- template< typename InputIterator >
- void insert( InputIterator first, InputIterator last ) // basic
- {
- map_basic_clone_and_insert( first, last );
- }
- template< class Range >
- void insert( const Range& r )
- {
- insert( boost::begin(r), boost::end(r) );
- }
- iterator insert( key_type& key, mapped_type x ) // strong
- {
- return insert_impl( key, x );
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- iterator insert( const key_type& key, std::auto_ptr<U> x )
- {
- return insert_impl( key, x.release() );
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- iterator insert( const key_type& key, std::unique_ptr<U> x )
- {
- return insert_impl( key, x.release() );
- }
- #endif
- template< class F, class S >
- iterator insert( iterator before, ptr_container_detail::ref_pair<F,S> p ) // strong
- {
- this->enforce_null_policy( p.second,
- "Null pointer in 'ptr_multimap_adapter::insert()'" );
- iterator res = insert_impl( before, p.first,
- this->null_policy_allocate_clone( p.second ) );
- return res;
- }
- iterator insert( iterator before, key_type& key, mapped_type x ) // strong
- {
- return insert_impl( before, key, x );
- }
- #ifndef BOOST_NO_AUTO_PTR
- template< class U >
- iterator insert( iterator before, const key_type& key, std::auto_ptr<U> x ) // strong
- {
- return insert_impl( before, key, x.release() );
- }
- #endif
- #ifndef BOOST_NO_CXX11_SMART_PTR
- template< class U >
- iterator insert( iterator before, const key_type& key, std::unique_ptr<U> x ) // strong
- {
- return insert_impl( before, key, x.release() );
- }
- #endif
-
- template< class PtrMapAdapter >
- void transfer( BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator object,
- PtrMapAdapter& from ) // strong
- {
- this->multi_transfer( object, from );
- }
- template< class PtrMapAdapter >
- size_type transfer( BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator first,
- BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator last,
- PtrMapAdapter& from ) // basic
- {
- return this->multi_transfer( first, last, from );
- }
- #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
- #else
- template< class PtrMapAdapter, class Range >
- BOOST_DEDUCED_TYPENAME boost::disable_if< boost::is_same< Range,
- BOOST_DEDUCED_TYPENAME PtrMapAdapter::iterator >,
- size_type >::type
- transfer( const Range& r, PtrMapAdapter& from ) // basic
- {
- return transfer( boost::begin(r), boost::end(r), from );
- }
- #endif
- template< class PtrMapAdapter >
- void transfer( PtrMapAdapter& from ) // basic
- {
- transfer( from.begin(), from.end(), from );
- BOOST_ASSERT( from.empty() );
- }
- };
- template< class I, class F, class S >
- inline bool is_null( const ptr_map_iterator<I,F,S>& i )
- {
- return i->second == 0;
- }
-
- } // namespace 'boost'
- #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
- #pragma GCC diagnostic pop
- #endif
- #endif
|