diff options
Diffstat (limited to 'boost/ptr_container/ptr_map_adapter.hpp')
-rw-r--r-- | boost/ptr_container/ptr_map_adapter.hpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/boost/ptr_container/ptr_map_adapter.hpp b/boost/ptr_container/ptr_map_adapter.hpp index f3ce83af89..4754a94977 100644 --- a/boost/ptr_container/ptr_map_adapter.hpp +++ b/boost/ptr_container/ptr_map_adapter.hpp @@ -170,12 +170,10 @@ namespace ptr_container_detail const_mapped_reference lookup( const key_type& key ) const { const_iterator i = this->find( key ); - if( i != this->end() ) - return *i->second; - else - BOOST_PTR_CONTAINER_THROW_EXCEPTION( true, bad_ptr_container_operation, - "'ptr_map/multimap::at()' could" - " not 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 @@ -343,17 +341,15 @@ namespace ptr_container_detail 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 ); - + 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 ); // nothrow - where.base()->second = ptr.release(); // nothrow, commit + auto_type old( where->second, *this ); // nothrow + where.base()->second = ptr.release(); // nothrow, commit return boost::ptr_container::move( old ); } @@ -425,7 +421,7 @@ namespace ptr_container_detail if( this->find( first->first ) == this->end() ) { const_reference p = *first.base(); // nothrow - auto_type ptr( this->null_policy_allocate_clone( p.second ) ); + auto_type ptr( this->null_policy_allocate_clone(p.second), *this ); // strong this->safe_insert( p.first, boost::ptr_container::move( ptr ) ); @@ -444,6 +440,11 @@ namespace ptr_container_detail 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, @@ -522,8 +523,8 @@ namespace ptr_container_detail 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 ); // nothrow + 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 @@ -535,7 +536,8 @@ namespace ptr_container_detail { this->enforce_null_policy( x, "Null pointer in 'ptr_map_adapter::insert()'" ); - auto_type ptr( x ); // nothrow + + 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 @@ -562,7 +564,7 @@ namespace ptr_container_detail this->enforce_null_policy( p.second, "Null pointer in 'ptr_map_adapter::insert()'" ); - auto_type ptr( this->null_policy_allocate_clone( p.second ) ); + 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 @@ -668,7 +670,7 @@ namespace ptr_container_detail while( first != last ) { const_reference pair = *first.base(); // nothrow - auto_type ptr( this->null_policy_allocate_clone( pair.second ) ); + auto_type ptr( this->null_policy_allocate_clone(pair.second), *this ); // strong safe_insert( pair.first, boost::ptr_container::move( ptr ) ); @@ -760,7 +762,8 @@ namespace ptr_container_detail { this->enforce_null_policy( x, "Null pointer in 'ptr_multimap_adapter::insert()'" ); - auto_type ptr( x ); // nothrow + + auto_type ptr( x, *this ); // nothrow BOOST_DEDUCED_TYPENAME base_type::ptr_iterator res = this->base().insert( std::make_pair( key, x ) ); // strong, commit @@ -772,7 +775,8 @@ namespace ptr_container_detail { this->enforce_null_policy( x, "Null pointer in 'ptr_multimap_adapter::insert()'" ); - auto_type ptr( x ); // nothrow + + auto_type ptr( x, *this ); // nothrow BOOST_DEDUCED_TYPENAME base_type::ptr_iterator res = this->base().insert( before.base(), std::make_pair( key, x ) ); |