tr1_impl/unordered_set

Go to the documentation of this file.
00001 // TR1 unordered_set -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008, 2009, 2010 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 1204.
00226     // NB: DR 675.
00227     this->clear();
00228     this->swap(__x);
00229     return *this;   
00230       }
00231 
00232       unordered_set&
00233       operator=(initializer_list<value_type> __l)
00234       {
00235     this->clear();
00236     this->insert(__l.begin(), __l.end());
00237     return *this;
00238       }
00239 #endif
00240     };
00241 
00242   /**
00243    *  @brief A standard container composed of equivalent keys
00244    *  (possibly containing multiple of each key value) in which the
00245    *  elements' keys are the elements themselves.
00246    *
00247    *  @ingroup unordered_associative_containers
00248    *
00249    *  Meets the requirements of a <a href="tables.html#65">container</a>, and
00250    *  <a href="tables.html#xx">unordered associative container</a>
00251    *
00252    *  @param  Value  Type of key objects.
00253    *  @param  Hash  Hashing function object type, defaults to hash<Value>.
00254    *  @param  Pred  Predicate function object type, defaults to equal_to<Value>.
00255    *  @param  Alloc  Allocator type, defaults to allocator<Key>.
00256    */
00257   template<class _Value,
00258        class _Hash = hash<_Value>,
00259        class _Pred = std::equal_to<_Value>,
00260        class _Alloc = std::allocator<_Value> >
00261     class unordered_multiset
00262     : public __unordered_multiset<_Value, _Hash, _Pred, _Alloc>
00263     {
00264       typedef __unordered_multiset<_Value, _Hash, _Pred, _Alloc>  _Base;
00265 
00266     public:
00267       typedef typename _Base::value_type      value_type;
00268       typedef typename _Base::size_type       size_type;
00269       typedef typename _Base::hasher          hasher;
00270       typedef typename _Base::key_equal       key_equal;
00271       typedef typename _Base::allocator_type  allocator_type;
00272       
00273       explicit
00274       unordered_multiset(size_type __n = 10,
00275              const hasher& __hf = hasher(),
00276              const key_equal& __eql = key_equal(),
00277              const allocator_type& __a = allocator_type())
00278       : _Base(__n, __hf, __eql, __a)
00279       { }
00280 
00281 
00282       template<typename _InputIterator>
00283         unordered_multiset(_InputIterator __f, _InputIterator __l, 
00284                typename _Base::size_type __n = 0,
00285                const hasher& __hf = hasher(), 
00286                const key_equal& __eql = key_equal(), 
00287                const allocator_type& __a = allocator_type())
00288     : _Base(__f, __l, __n, __hf, __eql, __a)
00289         { }
00290 
00291 #ifdef _GLIBCXX_INCLUDE_AS_CXX0X
00292       unordered_multiset(unordered_multiset&& __x)
00293       : _Base(std::forward<_Base>(__x)) { }
00294 
00295       unordered_multiset(initializer_list<value_type> __l,
00296              size_type __n = 10,
00297              const hasher& __hf = hasher(),
00298              const key_equal& __eql = key_equal(),
00299              const allocator_type& __a = allocator_type())
00300     : _Base(__l.begin(), __l.end(), __n, __hf, __eql, __a)
00301       { }
00302 
00303       unordered_multiset&
00304       operator=(unordered_multiset&& __x)
00305       {
00306     // NB: DR 1204.
00307     // NB: DR 675.
00308     this->clear();
00309     this->swap(__x);
00310     return *this;   
00311       }
00312 
00313       unordered_multiset&
00314       operator=(initializer_list<value_type> __l)
00315       {
00316     this->clear();
00317     this->insert(__l.begin(), __l.end());
00318     return *this;
00319       }
00320 #endif
00321     };
00322 
00323   template<class _Value, class _Hash, class _Pred, class _Alloc>
00324     inline void
00325     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
00326      unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
00327     { __x.swap(__y); }
00328 
00329   template<class _Value, class _Hash, class _Pred, class _Alloc>
00330     inline void
00331     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
00332      unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
00333     { __x.swap(__y); }
00334 
00335 _GLIBCXX_END_NAMESPACE_TR1
00336 }

Generated on 11 Jan 2010 for libstdc++ by  doxygen 1.6.1