Home | History | Annotate | Download | only in tr1_impl
      1 // TR1 unordered_set -*- C++ -*-
      2 
      3 // Copyright (C) 2007, 2009 Free Software Foundation, Inc.
      4 //
      5 // This file is part of the GNU ISO C++ Library.  This library is free
      6 // software; you can redistribute it and/or modify it under the
      7 // terms of the GNU General Public License as published by the
      8 // Free Software Foundation; either version 3, or (at your option)
      9 // any later version.
     10 
     11 // This library is distributed in the hope that it will be useful,
     12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 // GNU General Public License for more details.
     15 
     16 // Under Section 7 of GPL version 3, you are granted additional
     17 // permissions described in the GCC Runtime Library Exception, version
     18 // 3.1, as published by the Free Software Foundation.
     19 
     20 // You should have received a copy of the GNU General Public License and
     21 // a copy of the GCC Runtime Library Exception along with this program;
     22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23 // <http://www.gnu.org/licenses/>.
     24 
     25 /** @file tr1_impl/unordered_set
     26  *  This is an internal header file, included by other library headers.
     27  *  You should not attempt to use it directly.
     28  */
     29 
     30 namespace std
     31 { 
     32 _GLIBCXX_BEGIN_NAMESPACE_TR1
     33 
     34   // XXX When we get typedef templates these class definitions
     35   // will be unnecessary.
     36   template<class _Value,
     37 	   class _Hash = hash<_Value>,
     38 	   class _Pred = std::equal_to<_Value>,
     39 	   class _Alloc = std::allocator<_Value>,
     40 	   bool __cache_hash_code = false>
     41     class __unordered_set
     42     : public _Hashtable<_Value, _Value, _Alloc,
     43 			std::_Identity<_Value>, _Pred,
     44 			_Hash, __detail::_Mod_range_hashing,
     45 			__detail::_Default_ranged_hash,
     46 			__detail::_Prime_rehash_policy,
     47 			__cache_hash_code, true, true>
     48     {
     49       typedef _Hashtable<_Value, _Value, _Alloc,
     50 			 std::_Identity<_Value>, _Pred,
     51 			 _Hash, __detail::_Mod_range_hashing,
     52 			 __detail::_Default_ranged_hash,
     53 			 __detail::_Prime_rehash_policy,
     54 			 __cache_hash_code, true, true>
     55         _Base;
     56 
     57     public:
     58       typedef typename _Base::size_type       size_type;
     59       typedef typename _Base::hasher          hasher;
     60       typedef typename _Base::key_equal       key_equal;
     61       typedef typename _Base::allocator_type  allocator_type;
     62       
     63       explicit
     64       __unordered_set(size_type __n = 10,
     65 		      const hasher& __hf = hasher(),
     66 		      const key_equal& __eql = key_equal(),
     67 		      const allocator_type& __a = allocator_type())
     68       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
     69 	      __detail::_Default_ranged_hash(), __eql,
     70 	      std::_Identity<_Value>(), __a)
     71       { }
     72 
     73       template<typename _InputIterator>
     74         __unordered_set(_InputIterator __f, _InputIterator __l, 
     75 			size_type __n = 10,
     76 			const hasher& __hf = hasher(), 
     77 			const key_equal& __eql = key_equal(), 
     78 			const allocator_type& __a = allocator_type())
     79 	: _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
     80 		__detail::_Default_ranged_hash(), __eql,
     81 		std::_Identity<_Value>(), __a)
     82         { }
     83 
     84 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
     85       __unordered_set(__unordered_set&& __x)
     86       : _Base(std::forward<_Base>(__x)) { }
     87 #endif
     88     };
     89 
     90   template<class _Value,
     91 	   class _Hash = hash<_Value>,
     92 	   class _Pred = std::equal_to<_Value>,
     93 	   class _Alloc = std::allocator<_Value>,
     94 	   bool __cache_hash_code = false>
     95     class __unordered_multiset
     96     : public _Hashtable<_Value, _Value, _Alloc,
     97 			std::_Identity<_Value>, _Pred,
     98 			_Hash, __detail::_Mod_range_hashing,
     99 			__detail::_Default_ranged_hash,
    100 			__detail::_Prime_rehash_policy,
    101 			__cache_hash_code, true, false>
    102     {
    103       typedef _Hashtable<_Value, _Value, _Alloc,
    104 			 std::_Identity<_Value>, _Pred,
    105 			 _Hash, __detail::_Mod_range_hashing,
    106 			 __detail::_Default_ranged_hash,
    107 			 __detail::_Prime_rehash_policy,
    108 			 __cache_hash_code, true, false>
    109         _Base;
    110 
    111     public:
    112       typedef typename _Base::size_type       size_type;
    113       typedef typename _Base::hasher          hasher;
    114       typedef typename _Base::key_equal       key_equal;
    115       typedef typename _Base::allocator_type  allocator_type;
    116       
    117       explicit
    118       __unordered_multiset(size_type __n = 10,
    119 			   const hasher& __hf = hasher(),
    120 			   const key_equal& __eql = key_equal(),
    121 			   const allocator_type& __a = allocator_type())
    122       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
    123 	      __detail::_Default_ranged_hash(), __eql,
    124 	      std::_Identity<_Value>(), __a)
    125       { }
    126 
    127 
    128       template<typename _InputIterator>
    129         __unordered_multiset(_InputIterator __f, _InputIterator __l, 
    130 			     typename _Base::size_type __n = 0,
    131 			     const hasher& __hf = hasher(), 
    132 			     const key_equal& __eql = key_equal(), 
    133 			     const allocator_type& __a = allocator_type())
    134 	: _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
    135 		__detail::_Default_ranged_hash(), __eql,
    136 		std::_Identity<_Value>(), __a)
    137         { }
    138 
    139 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    140       __unordered_multiset(__unordered_multiset&& __x)
    141       : _Base(std::forward<_Base>(__x)) { }
    142 #endif
    143     };
    144 
    145   template<class _Value, class _Hash, class _Pred, class _Alloc,
    146 	   bool __cache_hash_code>
    147     inline void
    148     swap(__unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __x,
    149 	 __unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __y)
    150     { __x.swap(__y); }
    151 
    152   template<class _Value, class _Hash, class _Pred, class _Alloc,
    153 	   bool __cache_hash_code>
    154     inline void
    155     swap(__unordered_multiset<_Value, _Hash, _Pred,
    156 	 _Alloc, __cache_hash_code>& __x,
    157 	 __unordered_multiset<_Value, _Hash, _Pred,
    158 	 _Alloc, __cache_hash_code>& __y)
    159     { __x.swap(__y); }
    160 
    161 
    162   /**
    163    *  @brief A standard container composed of unique keys (containing
    164    *  at most one of each key value) in which the elements' keys are
    165    *  the elements themselves.
    166    *
    167    *  @ingroup unordered_associative_containers
    168    *
    169    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
    170    *  <a href="tables.html#xx">unordered associative container</a>
    171    *
    172    *  @param  Value  Type of key objects.
    173    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
    174    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
    175    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
    176    */
    177   template<class _Value,
    178 	   class _Hash = hash<_Value>,
    179 	   class _Pred = std::equal_to<_Value>,
    180 	   class _Alloc = std::allocator<_Value> >
    181     class unordered_set
    182     : public __unordered_set<_Value, _Hash, _Pred, _Alloc>
    183     {
    184       typedef __unordered_set<_Value, _Hash, _Pred, _Alloc>  _Base;
    185 
    186     public:
    187       typedef typename _Base::value_type      value_type;
    188       typedef typename _Base::size_type       size_type;
    189       typedef typename _Base::hasher          hasher;
    190       typedef typename _Base::key_equal       key_equal;
    191       typedef typename _Base::allocator_type  allocator_type;
    192       
    193       explicit
    194       unordered_set(size_type __n = 10,
    195 		    const hasher& __hf = hasher(),
    196 		    const key_equal& __eql = key_equal(),
    197 		    const allocator_type& __a = allocator_type())
    198       : _Base(__n, __hf, __eql, __a)
    199       { }
    200 
    201       template<typename _InputIterator>
    202         unordered_set(_InputIterator __f, _InputIterator __l, 
    203 		      size_type __n = 10,
    204 		      const hasher& __hf = hasher(), 
    205 		      const key_equal& __eql = key_equal(), 
    206 		      const allocator_type& __a = allocator_type())
    207 	: _Base(__f, __l, __n, __hf, __eql, __a)
    208         { }
    209 
    210 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    211       unordered_set(unordered_set&& __x)
    212       : _Base(std::forward<_Base>(__x)) { }
    213 
    214       unordered_set(initializer_list<value_type> __l,
    215 		    size_type __n = 10,
    216 		    const hasher& __hf = hasher(),
    217 		    const key_equal& __eql = key_equal(),
    218 		    const allocator_type& __a = allocator_type())
    219 	: _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
    220       { }
    221 
    222       unordered_set&
    223       operator=(unordered_set&& __x)
    224       {
    225 	// NB: DR 675.
    226 	this->clear();
    227 	this->swap(__x); 
    228 	return *this;	
    229       }
    230 
    231       unordered_set&
    232       operator=(initializer_list<value_type> __l)
    233       {
    234 	this->clear();
    235 	this->insert(__l.begin(), __l.end());
    236 	return *this;
    237       }
    238 #endif
    239     };
    240 
    241   /**
    242    *  @brief A standard container composed of equivalent keys
    243    *  (possibly containing multiple of each key value) in which the
    244    *  elements' keys are the elements themselves.
    245    *
    246    *  @ingroup unordered_associative_containers
    247    *
    248    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
    249    *  <a href="tables.html#xx">unordered associative container</a>
    250    *
    251    *  @param  Value  Type of key objects.
    252    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
    253    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
    254    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
    255    */
    256   template<class _Value,
    257 	   class _Hash = hash<_Value>,
    258 	   class _Pred = std::equal_to<_Value>,
    259 	   class _Alloc = std::allocator<_Value> >
    260     class unordered_multiset
    261     : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc>
    262     {
    263       typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc>  _Base;
    264 
    265     public:
    266       typedef typename _Base::value_type      value_type;
    267       typedef typename _Base::size_type       size_type;
    268       typedef typename _Base::hasher          hasher;
    269       typedef typename _Base::key_equal       key_equal;
    270       typedef typename _Base::allocator_type  allocator_type;
    271       
    272       explicit
    273       unordered_multiset(size_type __n = 10,
    274 			 const hasher& __hf = hasher(),
    275 			 const key_equal& __eql = key_equal(),
    276 			 const allocator_type& __a = allocator_type())
    277       : _Base(__n, __hf, __eql, __a)
    278       { }
    279 
    280 
    281       template<typename _InputIterator>
    282         unordered_multiset(_InputIterator __f, _InputIterator __l, 
    283 			   typename _Base::size_type __n = 0,
    284 			   const hasher& __hf = hasher(), 
    285 			   const key_equal& __eql = key_equal(), 
    286 			   const allocator_type& __a = allocator_type())
    287 	: _Base(__f, __l, __n, __hf, __eql, __a)
    288         { }
    289 
    290 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    291       unordered_multiset(unordered_multiset&& __x)
    292       : _Base(std::forward<_Base>(__x)) { }
    293 
    294       unordered_multiset(initializer_list<value_type> __l,
    295 			 size_type __n = 10,
    296 			 const hasher& __hf = hasher(),
    297 			 const key_equal& __eql = key_equal(),
    298 			 const allocator_type& __a = allocator_type())
    299 	: _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
    300       { }
    301 
    302       unordered_multiset&
    303       operator=(unordered_multiset&& __x)
    304       {
    305 	// NB: DR 675.
    306 	this->clear();
    307 	this->swap(__x); 
    308 	return *this;	
    309       }
    310 
    311       unordered_multiset&
    312       operator=(initializer_list<value_type> __l)
    313       {
    314 	this->clear();
    315 	this->insert(__l.begin(), __l.end());
    316 	return *this;
    317       }
    318 #endif
    319     };
    320 
    321   template<class _Value, class _Hash, class _Pred, class _Alloc>
    322     inline void
    323     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
    324 	 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
    325     { __x.swap(__y); }
    326 
    327   template<class _Value, class _Hash, class _Pred, class _Alloc>
    328     inline void
    329     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
    330 	 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
    331     { __x.swap(__y); }
    332 
    333 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    334   template<class _Value, class _Hash, class _Pred, class _Alloc>
    335     inline void
    336     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>&& __x,
    337 	 unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
    338     { __x.swap(__y); }
    339 
    340   template<class _Value, class _Hash, class _Pred, class _Alloc>
    341     inline void
    342     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
    343 	 unordered_set<_Value, _Hash, _Pred, _Alloc>&& __y)
    344     { __x.swap(__y); }
    345 
    346   template<class _Value, class _Hash, class _Pred, class _Alloc>
    347     inline void
    348     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __x,
    349 	 unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
    350     { __x.swap(__y); }
    351 
    352   template<class _Value, class _Hash, class _Pred, class _Alloc>
    353     inline void
    354     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
    355 	 unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __y)
    356     { __x.swap(__y); }
    357 #endif
    358 
    359 _GLIBCXX_END_NAMESPACE_TR1
    360 }
    361