# debug/unordered_set

Go to the documentation of this file.

    00001 // Debugging unordered_set/unordered_multiset implementation -*- C++ -*-
    00002
    00003 // Copyright (C) 2003, 2004, 2005, 2006, 2007
    00004 // Free Software Foundation, Inc.
    00005 //
    00006 // This file is part of the GNU ISO C++ Library.  This library is free
    00007 // software; you can redistribute it and/or modify it under the
    00008 // terms of the GNU General Public License as published by the
    00009 // Free Software Foundation; either version 2, or (at your option)
    00010 // any later version.
    00011
    00012 // This library is distributed in the hope that it will be useful,
    00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00015 // GNU General Public License for more details.
    00016
    00017 // You should have received a copy of the GNU General Public License along
    00018 // with this library; see the file COPYING.  If not, write to the Free
    00019 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
    00020 // USA.
    00021
    00022 // As a special exception, you may use this file as part of a free software
    00023 // library without restriction.  Specifically, if other files instantiate
    00024 // templates or use macros or inline functions from this file, or you compile
    00025 // this file and link it with other files to produce an executable, this
    00026 // file does not by itself cause the resulting executable to be covered by
    00027 // the GNU General Public License.  This exception does not however
    00028 // invalidate any other reasons why the executable file might be covered by
    00029 // the GNU General Public License.
    00030
    00031 /** @file debug/unordered_set
    00032  *  This file is a GNU debug extension to the Standard C++ Library.
    00033  */
    00034
    00035 #ifndef _GLIBCXX_DEBUG_UNORDERED_SET
    00036 #define _GLIBCXX_DEBUG_UNORDERED_SET 1
    00037
    00038 #ifdef __GXX_EXPERIMENTAL_CXX0X__
    00039 # include <unordered_set>
    00040 #else
    00041 # include <c++0x_warning.h>
    00042 #endif
    00043
    00044 #include <debug/safe_association.h>
    00045 #include <debug/safe_iterator.h>
    00046
    00047 #define _GLIBCXX_BASE unordered_set<_Value, _Hash, _Pred, _Alloc>
    00048 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
    00049
    00050 namespace std
    00051 {
    00052 namespace __debug
    00053 {
    00054   template<typename _Value,
    00055        typename _Hash  = std::hash<_Value>,
    00056        typename _Pred = std::equal_to<_Value>,
    00057        typename _Alloc =  std::allocator<_Value> >
    00058     class unordered_set
    00059     : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
    00060       public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
    00061     {
    00062       typedef typename _GLIBCXX_STD_BASE _Base;
    00063       typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
    00064       typedef __gnu_debug::_Safe_sequence<unordered_set> _Safe_base;
    00065
    00066     public:
    00067       typedef typename _Safe_assoc::size_type       size_type;
    00068       typedef typename _Safe_assoc::hasher          hasher;
    00069       typedef typename _Safe_assoc::key_equal       key_equal;
    00070       typedef typename _Safe_assoc::allocator_type allocator_type;
    00071
    00072       explicit
    00073       unordered_set(size_type __n = 10,
    00074             const hasher& __hf = hasher(),
    00075             const key_equal& __eql = key_equal(),
    00076             const allocator_type& __a = allocator_type())
    00077       : _Safe_assoc(__n, __hf, __eql, __a)
    00078       { }
    00079
    00080       template<typename _InputIterator>
    00081         unordered_set(_InputIterator __f, _InputIterator __l,
    00082               size_type __n = 10,
    00083               const hasher& __hf = hasher(),
    00084               const key_equal& __eql = key_equal(),
    00085               const allocator_type& __a = allocator_type())
    00086     : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
    00087         { }
    00088
    00089       unordered_set(const _Safe_assoc& __x)
    00090       : _Safe_assoc(__x), _Safe_base() { }
    00091
    00092       unordered_set(unordered_set&& __x)
    00093       : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
    00094
    00095       unordered_set&
    00096       operator=(unordered_set&& __x)
    00097       {
    00098         // NB: DR 675.
    00099     clear();
    00100     swap(__x);
    00101     return *this;
    00102       }
    00103
    00104       void
    00105       swap(unordered_set&& __x)
    00106       {
    00107     _Safe_assoc::swap(__x);
    00108     _Safe_base::_M_swap(__x);
    00109       }
    00110
    00111       void
    00112       clear()
    00113       {
    00114     _Base::clear();
    00115     this->_M_invalidate_all();
    00116       }
    00117
    00118     private:
    00119       void
    00120       _M_invalidate_all()
    00121       {
    00122     typedef typename _Base::const_iterator _Base_const_iterator;
    00123     typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
    00124     this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
    00125       }
    00126     };
    00127
    00128   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
    00129     inline void
    00130     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
    00131      unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
    00132     { __x.swap(__y); }
    00133
    00134   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
    00135     inline void
    00136     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>&& __x,
    00137      unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
    00138     { __x.swap(__y); }
    00139
    00140   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
    00141     inline void
    00142     swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
    00143      unordered_set<_Value, _Hash, _Pred, _Alloc>&& __y)
    00144     { __x.swap(__y); }
    00145
    00146 #undef _GLIBCXX_BASE
    00147 #undef _GLIBCXX_STD_BASE
    00148 #define _GLIBCXX_STD_BASE _GLIBCXX_STD_D::_GLIBCXX_BASE
    00149 #define _GLIBCXX_BASE unordered_multiset<_Value, _Hash, _Pred, _Alloc>
    00150
    00151   template<typename _Value,
    00152        typename _Hash  = std::hash<_Value>,
    00153        typename _Pred = std::equal_to<_Value>,
    00154        typename _Alloc =  std::allocator<_Value> >
    00155     class unordered_multiset
    00156     : public __gnu_debug::_Safe_association<_GLIBCXX_STD_BASE>,
    00157       public __gnu_debug::_Safe_sequence<_GLIBCXX_BASE>
    00158     {
    00159       typedef typename _GLIBCXX_STD_BASE _Base;
    00160       typedef __gnu_debug::_Safe_association<_Base> _Safe_assoc;
    00161       typedef __gnu_debug::_Safe_sequence<unordered_multiset> _Safe_base;
    00162
    00163     public:
    00164       typedef typename _Safe_assoc::size_type       size_type;
    00165       typedef typename _Safe_assoc::hasher          hasher;
    00166       typedef typename _Safe_assoc::key_equal       key_equal;
    00167       typedef typename _Safe_assoc::allocator_type allocator_type;
    00168
    00169       explicit
    00170       unordered_multiset(size_type __n = 10,
    00171             const hasher& __hf = hasher(),
    00172             const key_equal& __eql = key_equal(),
    00173             const allocator_type& __a = allocator_type())
    00174       : _Safe_assoc(__n, __hf, __eql, __a)
    00175       { }
    00176
    00177       template<typename _InputIterator>
    00178         unordered_multiset(_InputIterator __f, _InputIterator __l,
    00179               size_type __n = 10,
    00180               const hasher& __hf = hasher(),
    00181               const key_equal& __eql = key_equal(),
    00182               const allocator_type& __a = allocator_type())
    00183     : _Safe_assoc(__f, __l, __n, __hf, __eql, __a)
    00184         { }
    00185
    00186       unordered_multiset(const _Safe_assoc& __x)
    00187       : _Safe_assoc(__x), _Safe_base() { }
    00188
    00189       unordered_multiset(unordered_multiset&& __x)
    00190       : _Safe_assoc(std::forward<_Safe_assoc>(__x)), _Safe_base() { }
    00191
    00192       unordered_multiset&
    00193       operator=(unordered_multiset&& __x)
    00194       {
    00195         // NB: DR 675.
    00196     clear();
    00197     swap(__x);
    00198     return *this;
    00199       }
    00200
    00201       void
    00202       swap(unordered_multiset&& __x)
    00203       {
    00204     _Safe_assoc::swap(__x);
    00205     _Safe_base::_M_swap(__x);
    00206       }
    00207
    00208      void
    00209       clear()
    00210       {
    00211     _Base::clear();
    00212     this->_M_invalidate_all();
    00213       }
    00214
    00215     private:
    00216       void
    00217       _M_invalidate_all()
    00218       {
    00219     typedef typename _Base::const_iterator _Base_const_iterator;
    00220     typedef __gnu_debug::_Not_equal_to<_Base_const_iterator> _Not_equal;
    00221     this->_M_invalidate_if(_Not_equal(this->_M_base().end()));
    00222       }
    00223     };
    00224
    00225   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
    00226     inline void
    00227     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
    00228      unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
    00229     { __x.swap(__y); }
    00230
    00231   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
    00232     inline void
    00233     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __x,
    00234      unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
    00235     { __x.swap(__y); }
    00236
    00237   template<typename _Value, typename _Hash, typename _Pred, typename _Alloc>
    00238     inline void
    00239     swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
    00240      unordered_multiset<_Value, _Hash, _Pred, _Alloc>&& __y)
    00241     { __x.swap(__y); }
    00242
    00243 } // namespace __debug
    00244 } // namespace std
    00245
    00246 #undef _GLIBCXX_BASE
    00247 #undef _GLIBCXX_STD_BASE
    00248
    00249 #endif