# tr1_impl/unordered_set

Go to the documentation of this file.

    00001 // TR1 unordered_set -*- C++ -*-
    00002
    00003 // Copyright (C) 2007, 2009 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 3, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // Under Section 7 of GPL version 3, you are granted additional
    00017 // permissions described in the GCC Runtime Library Exception, version
    00018 // 3.1, as published by the Free Software Foundation.
    00019
    00020 // You should have received a copy of the GNU General Public License and
    00021 // a copy of the GCC Runtime Library Exception along with this program;
    00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
    00023 // <http://www.gnu.org/licenses/>.
    00024
    00025 /** @file tr1_impl/unordered_set
    00026  *  This is an internal header file, included by other library headers.
    00027  *  You should not attempt to use it directly.
    00028  */
    00029
    00030 namespace std
    00031 {
    00032 _GLIBCXX_BEGIN_NAMESPACE_TR1
    00033
    00034   // XXX When we get typedef templates these class definitions
    00035   // will be unnecessary.
    00036   template<class _Value,
    00037        class _Hash = hash<_Value>,
    00038        class _Pred = std::equal_to<_Value>,
    00039        class _Alloc = std::allocator<_Value>,
    00040        bool __cache_hash_code = false>
    00041     class __unordered_set
    00042     : public _Hashtable<_Value, _Value, _Alloc,
    00043             std::_Identity<_Value>, _Pred,
    00044             _Hash, __detail::_Mod_range_hashing,
    00045             __detail::_Default_ranged_hash,
    00046             __detail::_Prime_rehash_policy,
    00047             __cache_hash_code, true, true>
    00048     {
    00049       typedef _Hashtable<_Value, _Value, _Alloc,
    00050              std::_Identity<_Value>, _Pred,
    00051              _Hash, __detail::_Mod_range_hashing,
    00052              __detail::_Default_ranged_hash,
    00053              __detail::_Prime_rehash_policy,
    00054              __cache_hash_code, true, true>
    00055         _Base;
    00056
    00057     public:
    00058       typedef typename _Base::size_type       size_type;
    00059       typedef typename _Base::hasher          hasher;
    00060       typedef typename _Base::key_equal       key_equal;
    00061       typedef typename _Base::allocator_type  allocator_type;
    00062
    00063       explicit
    00064       __unordered_set(size_type __n = 10,
    00065               const hasher& __hf = hasher(),
    00066               const key_equal& __eql = key_equal(),
    00067               const allocator_type& __a = allocator_type())
    00068       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
    00069           __detail::_Default_ranged_hash(), __eql,
    00070           std::_Identity<_Value>(), __a)
    00071       { }
    00072
    00073       template<typename _InputIterator>
    00074         __unordered_set(_InputIterator __f, _InputIterator __l,
    00075             size_type __n = 10,
    00076             const hasher& __hf = hasher(),
    00077             const key_equal& __eql = key_equal(),
    00078             const allocator_type& __a = allocator_type())
    00079     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
    00080         __detail::_Default_ranged_hash(), __eql,
    00081         std::_Identity<_Value>(), __a)
    00082         { }
    00083
    00084 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00085       __unordered_set(__unordered_set&& __x)
    00086       : _Base(std::forward<_Base>(__x)) { }
    00087 #endif
    00088     };
    00089
    00090   template<class _Value,
    00091        class _Hash = hash<_Value>,
    00092        class _Pred = std::equal_to<_Value>,
    00093        class _Alloc = std::allocator<_Value>,
    00094        bool __cache_hash_code = false>
    00095     class __unordered_multiset
    00096     : public _Hashtable<_Value, _Value, _Alloc,
    00097             std::_Identity<_Value>, _Pred,
    00098             _Hash, __detail::_Mod_range_hashing,
    00099             __detail::_Default_ranged_hash,
    00100             __detail::_Prime_rehash_policy,
    00101             __cache_hash_code, true, false>
    00102     {
    00103       typedef _Hashtable<_Value, _Value, _Alloc,
    00104              std::_Identity<_Value>, _Pred,
    00105              _Hash, __detail::_Mod_range_hashing,
    00106              __detail::_Default_ranged_hash,
    00107              __detail::_Prime_rehash_policy,
    00108              __cache_hash_code, true, false>
    00109         _Base;
    00110
    00111     public:
    00112       typedef typename _Base::size_type       size_type;
    00113       typedef typename _Base::hasher          hasher;
    00114       typedef typename _Base::key_equal       key_equal;
    00115       typedef typename _Base::allocator_type  allocator_type;
    00116
    00117       explicit
    00118       __unordered_multiset(size_type __n = 10,
    00119                const hasher& __hf = hasher(),
    00120                const key_equal& __eql = key_equal(),
    00121                const allocator_type& __a = allocator_type())
    00122       : _Base(__n, __hf, __detail::_Mod_range_hashing(),
    00123           __detail::_Default_ranged_hash(), __eql,
    00124           std::_Identity<_Value>(), __a)
    00125       { }
    00126
    00127
    00128       template<typename _InputIterator>
    00129         __unordered_multiset(_InputIterator __f, _InputIterator __l,
    00130                  typename _Base::size_type __n = 0,
    00131                  const hasher& __hf = hasher(),
    00132                  const key_equal& __eql = key_equal(),
    00133                  const allocator_type& __a = allocator_type())
    00134     : _Base(__f, __l, __n, __hf, __detail::_Mod_range_hashing(),
    00135         __detail::_Default_ranged_hash(), __eql,
    00136         std::_Identity<_Value>(), __a)
    00137         { }
    00138
    00139 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00140       __unordered_multiset(__unordered_multiset&& __x)
    00141       : _Base(std::forward<_Base>(__x)) { }
    00142 #endif
    00143     };
    00144
    00145   template<class _Value, class _Hash, class _Pred, class _Alloc,
    00146        bool __cache_hash_code>
    00147     inline void
    00148     swap(__unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __x,
    00149      __unordered_set<_Value, _Hash, _Pred, _Alloc, __cache_hash_code>& __y)
    00150     { __x.swap(__y); }
    00151
    00152   template<class _Value, class _Hash, class _Pred, class _Alloc,
    00153        bool __cache_hash_code>
    00154     inline void
    00155     swap(__unordered_multiset<_Value, _Hash, _Pred,
    00156      _Alloc, __cache_hash_code>& __x,
    00157      __unordered_multiset<_Value, _Hash, _Pred,
    00158      _Alloc, __cache_hash_code>& __y)
    00159     { __x.swap(__y); }
    00160
    00161
    00162   /**
    00163    *  @brief A standard container composed of unique keys (containing
    00164    *  at most one of each key value) in which the elements' keys are
    00165    *  the elements themselves.
    00166    *
    00167    *  @ingroup unordered_associative_containers
    00168    *
    00169    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
    00170    *  <a href="tables.html#xx">unordered associative container</a>
    00171    *
    00172    *  @param  Value  Type of key objects.
    00173    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
    00174    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
    00175    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
    00176    */
    00177   template<class _Value,
    00178        class _Hash = hash<_Value>,
    00179        class _Pred = std::equal_to<_Value>,
    00180        class _Alloc = std::allocator<_Value> >
    00181     class unordered_set
    00182     : public __unordered_set<_Value, _Hash, _Pred, _Alloc>
    00183     {
    00184       typedef __unordered_set<_Value, _Hash, _Pred, _Alloc>  _Base;
    00185
    00186     public:
    00187       typedef typename _Base::value_type      value_type;
    00188       typedef typename _Base::size_type       size_type;
    00189       typedef typename _Base::hasher          hasher;
    00190       typedef typename _Base::key_equal       key_equal;
    00191       typedef typename _Base::allocator_type  allocator_type;
    00192
    00193       explicit
    00194       unordered_set(size_type __n = 10,
    00195             const hasher& __hf = hasher(),
    00196             const key_equal& __eql = key_equal(),
    00197             const allocator_type& __a = allocator_type())
    00198       : _Base(__n, __hf, __eql, __a)
    00199       { }
    00200
    00201       template<typename _InputIterator>
    00202         unordered_set(_InputIterator __f, _InputIterator __l,
    00203               size_type __n = 10,
    00204               const hasher& __hf = hasher(),
    00205               const key_equal& __eql = key_equal(),
    00206               const allocator_type& __a = allocator_type())
    00207     : _Base(__f, __l, __n, __hf, __eql, __a)
    00208         { }
    00209
    00210 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00211       unordered_set(unordered_set&& __x)
    00212       : _Base(std::forward<_Base>(__x)) { }
    00213
    00214       unordered_set(initializer_list<value_type> __l,
    00215             size_type __n = 10,
    00216             const hasher& __hf = hasher(),
    00217             const key_equal& __eql = key_equal(),
    00218             const allocator_type& __a = allocator_type())
    00219     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
    00220       { }
    00221
    00222       unordered_set&
    00223       operator=(unordered_set&& __x)
    00224       {
    00225     // NB: DR 675.
    00226     this->clear();
    00227     this->swap(__x);
    00228     return *this;
    00229       }
    00230
    00231       unordered_set&
    00232       operator=(initializer_list<value_type> __l)
    00233       {
    00234     this->clear();
    00235     this->insert(__l.begin(), __l.end());
    00236     return *this;
    00237       }
    00238 #endif
    00239     };
    00240
    00241   /**
    00242    *  @brief A standard container composed of equivalent keys
    00243    *  (possibly containing multiple of each key value) in which the
    00244    *  elements' keys are the elements themselves.
    00245    *
    00246    *  @ingroup unordered_associative_containers
    00247    *
    00248    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
    00249    *  <a href="tables.html#xx">unordered associative container</a>
    00250    *
    00251    *  @param  Value  Type of key objects.
    00252    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
    00253    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
    00254    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
    00255    */
    00256   template<class _Value,
    00257        class _Hash = hash<_Value>,
    00258        class _Pred = std::equal_to<_Value>,
    00259        class _Alloc = std::allocator<_Value> >
    00260     class unordered_multiset
    00261     : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc>
    00262     {
    00263       typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc>  _Base;
    00264
    00265     public:
    00266       typedef typename _Base::value_type      value_type;
    00267       typedef typename _Base::size_type       size_type;
    00268       typedef typename _Base::hasher          hasher;
    00269       typedef typename _Base::key_equal       key_equal;
    00270       typedef typename _Base::allocator_type  allocator_type;
    00271
    00272       explicit
    00273       unordered_multiset(size_type __n = 10,
    00274              const hasher& __hf = hasher(),
    00275              const key_equal& __eql = key_equal(),
    00276              const allocator_type& __a = allocator_type())
    00277       : _Base(__n, __hf, __eql, __a)
    00278       { }
    00279
    00280
    00281       template<typename _InputIterator>
    00282         unordered_multiset(_InputIterator __f, _InputIterator __l,
    00283                typename _Base::size_type __n = 0,
    00284                const hasher& __hf = hasher(),
    00285                const key_equal& __eql = key_equal(),
    00286                const allocator_type& __a = allocator_type())
    00287     : _Base(__f, __l, __n, __hf, __eql, __a)
    00288         { }
    00289
    00290 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00291       unordered_multiset(unordered_multiset&& __x)
    00292       : _Base(std::forward<_Base>(__x)) { }
    00293
    00294       unordered_multiset(initializer_list<value_type> __l,
    00295              size_type __n = 10,
    00296              const hasher& __hf = hasher(),
    00297              const key_equal& __eql = key_equal(),
    00298              const allocator_type& __a = allocator_type())
    00299     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
    00300       { }
    00301
    00302       unordered_multiset&
    00303       operator=(unordered_multiset&& __x)
    00304       {
    00305     // NB: DR 675.
    00306     this->clear();
    00307     this->swap(__x);
    00308     return *this;
    00309       }
    00310
    00311       unordered_multiset&
    00312       operator=(initializer_list<value_type> __l)
    00313       {
    00314     this->clear();
    00315     this->insert(__l.begin(), __l.end());
    00316     return *this;
    00317       }
    00318 #endif
    00319     };
    00320
    00321   template<class _Value, class _Hash, class _Pred, class _Alloc>
    00322     inline void
    00323     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
    00324      unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
    00325     { __x.swap(__y); }
    00326
    00327   template<class _Value, class _Hash, class _Pred, class _Alloc>
    00328     inline void
    00329     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
    00330      unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
    00331     { __x.swap(__y); }
    00332
    00333 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
    00334   template<class _Value, class _Hash, class _Pred, class _Alloc>
    00335     inline void
    00336     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>&& __x,
    00337      unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
    00338     { __x.swap(__y); }
    00339
    00340   template<class _Value, class _Hash, class _Pred, class _Alloc>
    00341     inline void
    00342     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
    00343      unordered_set<_Value, _Hash, _Pred, _Alloc>&& __y)
    00344     { __x.swap(__y); }
    00345
    00346   template<class _Value, class _Hash, class _Pred, class _Alloc>
    00347     inline void
    00348     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __x,
    00349      unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
    00350     { __x.swap(__y); }
    00351
    00352   template<class _Value, class _Hash, class _Pred, class _Alloc>
    00353     inline void
    00354     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
    00355      unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __y)
    00356     { __x.swap(__y); }
    00357 #endif
    00358
    00359 _GLIBCXX_END_NAMESPACE_TR1
    00360 }