Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:34

0001 //
0002 // Boost.Pointer Container
0003 //
0004 //  Copyright Thorsten Ottosen 2003-2005. Use, modification and
0005 //  distribution is subject to the Boost Software License, Version
0006 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 //  http://www.boost.org/LICENSE_1_0.txt)
0008 //
0009 // For more information, see http://www.boost.org/libs/ptr_container/
0010 //
0011 
0012 
0013 #ifndef BOOST_PTR_CONTAINER_DETAIL_ASSOCIATIVE_PTR_CONTAINER_HPP
0014 #define BOOST_PTR_CONTAINER_DETAIL_ASSOCIATIVE_PTR_CONTAINER_HPP
0015 
0016 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0017 # pragma once
0018 #endif
0019 
0020 #include <boost/ptr_container/detail/reversible_ptr_container.hpp>
0021 #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
0022 
0023 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
0024 #pragma GCC diagnostic push
0025 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
0026 #endif
0027 
0028 namespace boost
0029 {
0030 
0031 namespace ptr_container_detail
0032 {
0033     template
0034     <
0035         class Config,
0036         class CloneAllocator
0037     >
0038     class associative_ptr_container :
0039         public reversible_ptr_container<Config,CloneAllocator>
0040     {
0041         typedef reversible_ptr_container<Config,CloneAllocator>
0042                                 base_type;
0043 
0044         typedef BOOST_DEDUCED_TYPENAME base_type::scoped_deleter
0045                                 scoped_deleter;
0046 
0047         typedef BOOST_DEDUCED_TYPENAME Config::container_type
0048                                 container_type;
0049     public: // typedefs
0050         typedef BOOST_DEDUCED_TYPENAME Config::key_type
0051                                 key_type;
0052         typedef BOOST_DEDUCED_TYPENAME Config::key_compare
0053                                 key_compare;
0054         typedef BOOST_DEDUCED_TYPENAME Config::value_compare
0055                                 value_compare;
0056         typedef BOOST_DEDUCED_TYPENAME Config::hasher
0057                                 hasher;
0058         typedef BOOST_DEDUCED_TYPENAME Config::key_equal
0059                                 key_equal;
0060         typedef BOOST_DEDUCED_TYPENAME Config::iterator
0061                                 iterator;
0062         typedef BOOST_DEDUCED_TYPENAME Config::const_iterator
0063                                 const_iterator;
0064         typedef BOOST_DEDUCED_TYPENAME Config::local_iterator
0065                                 local_iterator;
0066         typedef BOOST_DEDUCED_TYPENAME Config::const_local_iterator
0067                                 const_local_iterator;
0068         typedef BOOST_DEDUCED_TYPENAME base_type::size_type
0069                                 size_type;
0070         typedef BOOST_DEDUCED_TYPENAME base_type::reference
0071                                 reference;
0072         typedef BOOST_DEDUCED_TYPENAME base_type::const_reference
0073                     const_reference;
0074 
0075     public: // foundation
0076         associative_ptr_container()
0077         { }
0078 
0079         template< class SizeType >
0080         associative_ptr_container( SizeType n, unordered_associative_container_tag tag )
0081           : base_type( n, tag )
0082         { }
0083 
0084         template< class Compare, class Allocator >
0085         associative_ptr_container( const Compare& comp,
0086                                    const Allocator& a )
0087          : base_type( comp, a, container_type() )
0088         { }
0089 
0090         template< class Hash, class Pred, class Allocator >
0091         associative_ptr_container( const Hash& hash,
0092                                    const Pred& pred,
0093                                    const Allocator& a )
0094          : base_type( hash, pred, a )
0095         { }
0096 
0097         template< class InputIterator, class Compare, class Allocator >
0098         associative_ptr_container( InputIterator first, InputIterator last,
0099                                    const Compare& comp,
0100                                    const Allocator& a )
0101          : base_type( first, last, comp, a, container_type() )
0102         { }
0103 
0104         template< class InputIterator, class Hash, class Pred, class Allocator >
0105         associative_ptr_container( InputIterator first, InputIterator last,
0106                                    const Hash& hash,
0107                                    const Pred& pred,
0108                                    const Allocator& a )
0109          : base_type( first, last, hash, pred, a )
0110         { }
0111 
0112 #ifndef BOOST_NO_AUTO_PTR
0113         template< class PtrContainer >
0114         explicit associative_ptr_container( std::auto_ptr<PtrContainer> r )
0115          : base_type( r )
0116         { }
0117 #endif
0118 #ifndef BOOST_NO_CXX11_SMART_PTR
0119         template< class PtrContainer >
0120         explicit associative_ptr_container( std::unique_ptr<PtrContainer> r )
0121          : base_type( std::move( r ) )
0122         { }
0123 #endif
0124 
0125         associative_ptr_container( const associative_ptr_container& r )
0126          : base_type( r.begin(), r.end(), container_type() )
0127         { }
0128 
0129         template< class C, class V >
0130         associative_ptr_container( const associative_ptr_container<C,V>& r )
0131          : base_type( r.begin(), r.end(), container_type() )
0132         { }
0133 
0134 #ifndef BOOST_NO_AUTO_PTR
0135         template< class PtrContainer >
0136         associative_ptr_container& operator=( std::auto_ptr<PtrContainer> r ) // nothrow
0137         {
0138            base_type::operator=( r );
0139            return *this;
0140         }
0141 #endif
0142 #ifndef BOOST_NO_CXX11_SMART_PTR
0143         template< class PtrContainer >
0144         associative_ptr_container& operator=( std::unique_ptr<PtrContainer> r ) // nothrow
0145         {
0146            base_type::operator=( std::move( r ) );
0147            return *this;
0148         }
0149 #endif
0150 
0151         associative_ptr_container& operator=( associative_ptr_container r ) // strong
0152         {
0153            this->swap( r );
0154            return *this;
0155         }
0156 
0157     public: // associative container interface
0158         key_compare key_comp() const
0159         {
0160             return this->base().key_comp();
0161         }
0162 
0163         value_compare value_comp() const
0164         {
0165             return this->base().value_comp();
0166         }
0167 
0168         iterator erase( iterator before ) // nothrow
0169         {
0170             BOOST_ASSERT( !this->empty() );
0171             BOOST_ASSERT( before != this->end() );
0172 
0173             this->remove( before );                      // nothrow
0174             iterator res( before );                      // nothrow
0175             ++res;                                       // nothrow
0176             this->base().erase( before.base() );         // nothrow
0177             return res;                                  // nothrow
0178         }
0179 
0180         size_type erase( const key_type& x ) // nothrow
0181         {
0182             iterator i( this->base().find( x ) );
0183                                                         // nothrow
0184             if( i == this->end() )                      // nothrow
0185                 return 0u;                              // nothrow
0186             this->remove( i );                          // nothrow
0187             return this->base().erase( x );             // nothrow
0188         }
0189 
0190         iterator erase( iterator first,
0191                         iterator last ) // nothrow
0192         {
0193             iterator res( last );                                // nothrow
0194             if( res != this->end() )
0195                 ++res;                                           // nothrow
0196 
0197             this->remove( first, last );                         // nothrow
0198             this->base().erase( first.base(), last.base() );     // nothrow
0199             return res;                                          // nothrow
0200         }
0201 
0202 #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
0203 #else
0204         template< class Range >
0205         BOOST_DEDUCED_TYPENAME boost::disable_if< boost::is_convertible<Range&,key_type&>,
0206                                                   iterator >::type
0207         erase( const Range& r )
0208         {
0209             return erase( boost::begin(r), boost::end(r) );
0210         }
0211 
0212 #endif
0213 
0214     protected:
0215 
0216         template< class AssociatePtrCont >
0217         void multi_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator object,
0218                              AssociatePtrCont& from ) // strong
0219         {
0220             BOOST_ASSERT( (void*)&from != (void*)this );
0221             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
0222 
0223             this->base().insert( *object.base() );     // strong
0224             from.base().erase( object.base() );        // nothrow
0225         }
0226 
0227         template< class AssociatePtrCont >
0228         size_type multi_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator first,
0229                                   BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator last,
0230                                   AssociatePtrCont& from ) // basic
0231         {
0232             BOOST_ASSERT( (void*)&from != (void*)this );
0233 
0234             size_type res = 0;
0235             for( ; first != last; )
0236             {
0237                 BOOST_ASSERT( first != from.end() );
0238                 this->base().insert( *first.base() );     // strong
0239                 BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator
0240                     to_delete( first );
0241                 ++first;
0242                 from.base().erase( to_delete.base() );    // nothrow
0243                 ++res;
0244             }
0245 
0246             return res;
0247         }
0248 
0249         template< class AssociatePtrCont >
0250         bool single_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator object,
0251                               AssociatePtrCont& from ) // strong
0252         {
0253             BOOST_ASSERT( (void*)&from != (void*)this );
0254             BOOST_ASSERT( !from.empty() && "Cannot transfer from empty container" );
0255 
0256             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool> p =
0257                 this->base().insert( *object.base() );     // strong
0258             if( p.second )
0259                 from.base().erase( object.base() );        // nothrow
0260 
0261             return p.second;
0262         }
0263 
0264         template< class AssociatePtrCont >
0265         size_type single_transfer( BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator first,
0266                                    BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator last,
0267                                    AssociatePtrCont& from ) // basic
0268         {
0269             BOOST_ASSERT( (void*)&from != (void*)this );
0270 
0271             size_type res = 0;
0272             for( ; first != last; )
0273             {
0274                 BOOST_ASSERT( first != from.end() );
0275                 std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool> p =
0276                     this->base().insert( *first.base() );     // strong
0277                 BOOST_DEDUCED_TYPENAME AssociatePtrCont::iterator
0278                     to_delete( first );
0279                 ++first;
0280                 if( p.second )
0281                 {
0282                     from.base().erase( to_delete.base() );   // nothrow
0283                     ++res;
0284                 }
0285             }
0286             return res;
0287         }
0288 
0289         reference front()
0290         {
0291             BOOST_ASSERT( !this->empty() );
0292             BOOST_ASSERT( *this->begin().base() != 0 );
0293             return *this->begin();
0294         }
0295 
0296         const_reference front() const
0297         {
0298             return const_cast<associative_ptr_container*>(this)->front();
0299         }
0300 
0301         reference back()
0302         {
0303             BOOST_ASSERT( !this->empty() );
0304             BOOST_ASSERT( *(--this->end()).base() != 0 );
0305             return *--this->end();
0306         }
0307 
0308         const_reference back() const
0309         {
0310             return const_cast<associative_ptr_container*>(this)->back();
0311         }
0312 
0313     protected: // unordered interface
0314         hasher hash_function() const
0315         {
0316             return this->base().hash_function();
0317         }
0318 
0319         key_equal key_eq() const
0320         {
0321             return this->base().key_eq();
0322         }
0323 
0324         size_type bucket_count() const
0325         {
0326             return this->base().bucket_count();
0327         }
0328 
0329         size_type max_bucket_count() const
0330         {
0331             return this->base().max_bucket_count();
0332         }
0333 
0334         size_type bucket_size( size_type n ) const
0335         {
0336             return this->base().bucket_size( n );
0337         }
0338 
0339         float load_factor() const
0340         {
0341             return this->base().load_factor();
0342         }
0343 
0344         float max_load_factor() const
0345         {
0346             return this->base().max_load_factor();
0347         }
0348 
0349         void max_load_factor( float factor )
0350         {
0351             return this->base().max_load_factor( factor );
0352         }
0353 
0354         void rehash( size_type n )
0355         {
0356             this->base().rehash( n );
0357         }
0358 
0359     public:
0360 #if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(70190006))
0361         iterator begin()
0362         {
0363             return base_type::begin();
0364         }
0365 
0366         const_iterator begin() const
0367         {
0368             return base_type::begin();
0369         }
0370 
0371         iterator end()
0372         {
0373             return base_type::end();
0374         }
0375 
0376         const_iterator end() const
0377         {
0378             return base_type::end();
0379         }
0380 
0381         const_iterator cbegin() const
0382         {
0383             return base_type::cbegin();
0384         }
0385 
0386         const_iterator cend() const
0387         {
0388             return base_type::cend();
0389         }
0390 #else
0391          using base_type::begin;
0392          using base_type::end;
0393          using base_type::cbegin;
0394          using base_type::cend;
0395 #endif
0396 
0397     protected:
0398         local_iterator begin( size_type n )
0399         {
0400             return local_iterator( this->base().begin( n ) );
0401         }
0402 
0403         const_local_iterator begin( size_type n ) const
0404         {
0405             return const_local_iterator( this->base().begin( n ) );
0406         }
0407 
0408         local_iterator end( size_type n )
0409         {
0410             return local_iterator( this->base().end( n ) );
0411         }
0412 
0413         const_local_iterator end( size_type n ) const
0414         {
0415             return const_local_iterator( this->base().end( n ) );
0416         }
0417 
0418         const_local_iterator cbegin( size_type n ) const
0419         {
0420             return const_local_iterator( this->base().cbegin( n ) );
0421         }
0422 
0423         const_local_iterator cend( size_type n )
0424         {
0425             return const_local_iterator( this->base().cend( n ) );
0426         }
0427 
0428      }; // class 'associative_ptr_container'
0429 
0430 } // namespace 'ptr_container_detail'
0431 
0432 } // namespace 'boost'
0433 
0434 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
0435 #pragma GCC diagnostic pop
0436 #endif
0437 
0438 #endif