29 #ifndef _GLIBCXX_DEBUG_UNORDERED_SET
30 #define _GLIBCXX_DEBUG_UNORDERED_SET 1
32 #if __cplusplus < 201103L
41 namespace std _GLIBCXX_VISIBILITY(default)
46 template<
typename _Value,
51 :
public _GLIBCXX_STD_C::unordered_set<_Value, _Hash, _Pred, _Alloc>,
55 typedef _GLIBCXX_STD_C::unordered_set<_Value, _Hash,
58 typedef typename _Base::const_iterator _Base_const_iterator;
59 typedef typename _Base::iterator _Base_iterator;
60 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
61 typedef typename _Base::local_iterator _Base_local_iterator;
66 typedef typename _Base::size_type size_type;
67 typedef typename _Base::hasher hasher;
68 typedef typename _Base::key_equal key_equal;
69 typedef typename _Base::allocator_type allocator_type;
71 typedef typename _Base::key_type key_type;
72 typedef typename _Base::value_type value_type;
85 const hasher& __hf = hasher(),
86 const key_equal& __eql = key_equal(),
87 const allocator_type& __a = allocator_type())
88 :
_Base(__n, __hf, __eql, __a) { }
90 template<
typename _InputIterator>
93 const hasher& __hf = hasher(),
94 const key_equal& __eql = key_equal(),
95 const allocator_type& __a = allocator_type())
114 const allocator_type& __a)
115 :
_Base(__uset._M_base(), __a)
119 const allocator_type& __a)
120 :
_Base(std::move(__uset._M_base()), __a)
125 const hasher& __hf = hasher(),
126 const key_equal& __eql = key_equal(),
127 const allocator_type& __a = allocator_type())
128 :
_Base(__l, __n, __hf, __eql, __a) { }
135 _M_base() = __x._M_base();
136 this->_M_invalidate_all();
142 noexcept(_Alloc_traits::_S_nothrow_move())
144 __glibcxx_check_self_move_assign(__x);
145 bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
146 || __x.get_allocator() == this->get_allocator();
147 _M_base() = std::move(__x._M_base());
151 this->_M_invalidate_all();
152 __x._M_invalidate_all();
160 this->_M_invalidate_all();
166 noexcept(_Alloc_traits::_S_nothrow_swap())
168 if (!_Alloc_traits::_S_propagate_on_swap())
169 __glibcxx_check_equal_allocs(__x);
178 this->_M_invalidate_all();
183 {
return iterator(_Base::begin(),
this); }
186 begin()
const noexcept
191 {
return iterator(_Base::end(),
this); }
198 cbegin()
const noexcept
202 cend()
const noexcept
209 __glibcxx_check_bucket_index(__b);
216 __glibcxx_check_bucket_index(__b);
221 begin(size_type __b)
const
223 __glibcxx_check_bucket_index(__b);
228 end(size_type __b)
const
230 __glibcxx_check_bucket_index(__b);
235 cbegin(size_type __b)
const
237 __glibcxx_check_bucket_index(__b);
242 cend(size_type __b)
const
244 __glibcxx_check_bucket_index(__b);
249 bucket_size(size_type __b)
const
251 __glibcxx_check_bucket_index(__b);
252 return _Base::bucket_size(__b);
256 max_load_factor()
const noexcept
257 {
return _Base::max_load_factor(); }
260 max_load_factor(
float __f)
262 __glibcxx_check_max_load_factor(__f);
263 _Base::max_load_factor(__f);
266 template<
typename... _Args>
268 emplace(_Args&&... __args)
270 size_type __bucket_count = this->bucket_count();
272 = _Base::emplace(std::forward<_Args>(__args)...);
273 _M_check_rehashed(__bucket_count);
277 template<
typename... _Args>
282 size_type __bucket_count = this->bucket_count();
283 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
284 std::forward<_Args>(__args)...);
285 _M_check_rehashed(__bucket_count);
290 insert(
const value_type& __obj)
292 size_type __bucket_count = this->bucket_count();
294 __pair_type __res = _Base::insert(__obj);
295 _M_check_rehashed(__bucket_count);
303 size_type __bucket_count = this->bucket_count();
304 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
305 _M_check_rehashed(__bucket_count);
310 insert(value_type&& __obj)
312 size_type __bucket_count = this->bucket_count();
314 __pair_type __res = _Base::insert(std::move(__obj));
315 _M_check_rehashed(__bucket_count);
323 size_type __bucket_count = this->bucket_count();
324 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
325 _M_check_rehashed(__bucket_count);
332 size_type __bucket_count = this->bucket_count();
334 _M_check_rehashed(__bucket_count);
337 template<
typename _InputIterator>
339 insert(_InputIterator __first, _InputIterator __last)
341 __glibcxx_check_valid_range(__first, __last);
342 size_type __bucket_count = this->bucket_count();
345 _M_check_rehashed(__bucket_count);
349 find(
const key_type& __key)
350 {
return iterator(_Base::find(__key),
this); }
353 find(
const key_type& __key)
const
357 equal_range(
const key_type& __key)
360 __pair_type __res = _Base::equal_range(__key);
366 equal_range(
const key_type& __key)
const
369 __res = _Base::equal_range(__key);
375 erase(
const key_type& __key)
378 _Base_iterator __victim(_Base::find(__key));
379 if (__victim != _Base::end())
382 [__victim](_Base_const_iterator __it)
383 {
return __it == __victim; });
385 [__victim](_Base_const_local_iterator __it)
386 {
return __it._M_cur == __victim._M_cur; });
387 size_type __bucket_count = this->bucket_count();
388 _Base::erase(__victim);
389 _M_check_rehashed(__bucket_count);
399 _Base_const_iterator __victim = __it.
base();
401 [__victim](_Base_const_iterator __it)
402 {
return __it == __victim; });
404 [__victim](_Base_const_local_iterator __it)
405 {
return __it._M_cur == __victim._M_cur; });
406 size_type __bucket_count = this->bucket_count();
407 _Base_iterator __next = _Base::erase(__it.base());
408 _M_check_rehashed(__bucket_count);
420 for (_Base_const_iterator __tmp = __first.
base();
421 __tmp != __last.
base(); ++__tmp)
423 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
424 _M_message(__gnu_debug::__msg_valid_range)
425 ._M_iterator(__first,
"first")
426 ._M_iterator(__last,
"last"));
428 [__tmp](_Base_const_iterator __it)
429 {
return __it == __tmp; });
431 [__tmp](_Base_const_local_iterator __it)
432 {
return __it._M_cur == __tmp._M_cur; });
434 size_type __bucket_count = this->bucket_count();
435 _Base_iterator __next = _Base::erase(__first.
base(),
437 _M_check_rehashed(__bucket_count);
442 _M_base() noexcept {
return *
this; }
445 _M_base()
const noexcept {
return *
this; }
449 _M_invalidate_locals()
451 _Base_local_iterator __local_end = _Base::end(0);
453 [__local_end](_Base_const_local_iterator __it)
454 {
return __it != __local_end; });
460 _Base_iterator __end = _Base::end();
462 [__end](_Base_const_iterator __it)
463 {
return __it != __end; });
464 _M_invalidate_locals();
468 _M_check_rehashed(size_type __prev_count)
470 if (__prev_count != this->bucket_count())
471 _M_invalidate_locals();
475 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
481 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
485 {
return __x._M_base() == __y._M_base(); }
487 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
489 operator!=(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
490 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
491 {
return !(__x == __y); }
495 template<
typename _Value,
500 :
public _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash, _Pred, _Alloc>,
502 unordered_multiset<_Value, _Hash, _Pred, _Alloc> >
504 typedef _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash,
505 _Pred, _Alloc>
_Base;
508 typedef typename _Base::const_iterator _Base_const_iterator;
509 typedef typename _Base::iterator _Base_iterator;
510 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
511 typedef typename _Base::local_iterator _Base_local_iterator;
517 typedef typename _Base::size_type size_type;
518 typedef typename _Base::hasher hasher;
519 typedef typename _Base::key_equal key_equal;
520 typedef typename _Base::allocator_type allocator_type;
522 typedef typename _Base::key_type key_type;
523 typedef typename _Base::value_type value_type;
536 const hasher& __hf = hasher(),
537 const key_equal& __eql = key_equal(),
538 const allocator_type& __a = allocator_type())
539 :
_Base(__n, __hf, __eql, __a) { }
541 template<
typename _InputIterator>
544 const hasher& __hf = hasher(),
545 const key_equal& __eql = key_equal(),
546 const allocator_type& __a = allocator_type())
550 __hf, __eql, __a) { }
565 const allocator_type& __a)
566 :
_Base(__uset._M_base(), __a)
570 const allocator_type& __a)
571 :
_Base(std::move(__uset._M_base()), __a)
576 const hasher& __hf = hasher(),
577 const key_equal& __eql = key_equal(),
578 const allocator_type& __a = allocator_type())
579 :
_Base(__l, __n, __hf, __eql, __a) { }
586 _M_base() = __x._M_base();
587 this->_M_invalidate_all();
593 noexcept(_Alloc_traits::_S_nothrow_move())
595 __glibcxx_check_self_move_assign(__x);
596 bool xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
597 || __x.get_allocator() == this->get_allocator();
598 _M_base() = std::move(__x._M_base());
602 this->_M_invalidate_all();
603 __x._M_invalidate_all();
611 this->_M_invalidate_all();
617 noexcept(_Alloc_traits::_S_nothrow_swap())
619 if (!_Alloc_traits::_S_propagate_on_swap())
620 __glibcxx_check_equal_allocs(__x);
629 this->_M_invalidate_all();
634 {
return iterator(_Base::begin(),
this); }
637 begin()
const noexcept
642 {
return iterator(_Base::end(),
this); }
649 cbegin()
const noexcept
653 cend()
const noexcept
660 __glibcxx_check_bucket_index(__b);
667 __glibcxx_check_bucket_index(__b);
672 begin(size_type __b)
const
674 __glibcxx_check_bucket_index(__b);
679 end(size_type __b)
const
681 __glibcxx_check_bucket_index(__b);
686 cbegin(size_type __b)
const
688 __glibcxx_check_bucket_index(__b);
693 cend(size_type __b)
const
695 __glibcxx_check_bucket_index(__b);
700 bucket_size(size_type __b)
const
702 __glibcxx_check_bucket_index(__b);
703 return _Base::bucket_size(__b);
707 max_load_factor()
const noexcept
708 {
return _Base::max_load_factor(); }
711 max_load_factor(
float __f)
713 __glibcxx_check_max_load_factor(__f);
714 _Base::max_load_factor(__f);
717 template<
typename... _Args>
719 emplace(_Args&&... __args)
721 size_type __bucket_count = this->bucket_count();
723 = _Base::emplace(std::forward<_Args>(__args)...);
724 _M_check_rehashed(__bucket_count);
728 template<
typename... _Args>
733 size_type __bucket_count = this->bucket_count();
734 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
735 std::forward<_Args>(__args)...);
736 _M_check_rehashed(__bucket_count);
741 insert(
const value_type& __obj)
743 size_type __bucket_count = this->bucket_count();
744 _Base_iterator __it = _Base::insert(__obj);
745 _M_check_rehashed(__bucket_count);
753 size_type __bucket_count = this->bucket_count();
754 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
755 _M_check_rehashed(__bucket_count);
760 insert(value_type&& __obj)
762 size_type __bucket_count = this->bucket_count();
763 _Base_iterator __it = _Base::insert(std::move(__obj));
764 _M_check_rehashed(__bucket_count);
772 size_type __bucket_count = this->bucket_count();
773 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
774 _M_check_rehashed(__bucket_count);
781 size_type __bucket_count = this->bucket_count();
783 _M_check_rehashed(__bucket_count);
786 template<
typename _InputIterator>
788 insert(_InputIterator __first, _InputIterator __last)
790 __glibcxx_check_valid_range(__first, __last);
791 size_type __bucket_count = this->bucket_count();
794 _M_check_rehashed(__bucket_count);
798 find(
const key_type& __key)
799 {
return iterator(_Base::find(__key),
this); }
802 find(
const key_type& __key)
const
806 equal_range(
const key_type& __key)
809 __pair_type __res = _Base::equal_range(__key);
815 equal_range(
const key_type& __key)
const
818 __res = _Base::equal_range(__key);
824 erase(
const key_type& __key)
828 _Base::equal_range(__key);
829 for (_Base_iterator __victim = __pair.
first; __victim != __pair.
second;)
832 {
return __it == __victim; });
834 [__victim](_Base_const_local_iterator __it)
835 {
return __it._M_cur == __victim._M_cur; });
836 _Base::erase(__victim++);
846 _Base_const_iterator __victim = __it.
base();
848 {
return __it == __victim; });
850 [__victim](_Base_const_local_iterator __it)
851 {
return __it._M_cur == __victim._M_cur; });
852 return iterator(_Base::erase(__it.base()),
this);
863 for (_Base_const_iterator __tmp = __first.
base();
864 __tmp != __last.
base(); ++__tmp)
866 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
867 _M_message(__gnu_debug::__msg_valid_range)
868 ._M_iterator(__first,
"first")
869 ._M_iterator(__last,
"last"));
871 {
return __it == __tmp; });
873 [__tmp](_Base_const_local_iterator __it)
874 {
return __it._M_cur == __tmp._M_cur; });
877 __last.
base()),
this);
881 _M_base() noexcept {
return *
this; }
884 _M_base()
const noexcept {
return *
this; }
888 _M_invalidate_locals()
890 _Base_local_iterator __local_end = _Base::end(0);
892 [__local_end](_Base_const_local_iterator __it)
893 {
return __it != __local_end; });
899 _Base_iterator __end = _Base::end();
901 {
return __it != __end; });
902 _M_invalidate_locals();
906 _M_check_rehashed(size_type __prev_count)
908 if (__prev_count != this->bucket_count())
909 _M_invalidate_locals();
913 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
919 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
923 {
return __x._M_base() == __y._M_base(); }
925 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
927 operator!=(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
928 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
929 {
return !(__x == __y); }
Base class for constructing a safe unordered container type that tracks iterators that reference it...
_T2 second
first is a copy of the first object
void _M_invalidate_local_if(_Predicate __pred)
#define __glibcxx_check_insert(_Position)
Uniform interface to C++98 and C++0x allocators.
constexpr pair< typename __decay_and_strip< _T1 >::__type, typename __decay_and_strip< _T2 >::__type > make_pair(_T1 &&__x, _T2 &&__y)
A convenience wrapper for creating a pair from two objects.
_T1 first
second_type is the second bound type
void _M_invalidate_if(_Predicate __pred)
Struct holding two objects of arbitrary type.
void _M_swap(_Safe_unordered_container_base &__x)
Class std::unordered_set with safety/checking/debug instrumentation.
Base class that supports tracking of iterators that reference a sequence.
A standard container composed of unique keys (containing at most one of each key value) in which the ...
_Iterator base() const noexcept
Return the underlying iterator.
#define __glibcxx_check_erase(_Position)
Class std::unordered_multiset with safety/checking/debug instrumentation.
The standard allocator, as per [20.4].
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
A standard container composed of equivalent keys (possibly containing multiple of each key value) in ...
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
One of the comparison functors.
Primary class template hash.
#define __glibcxx_check_erase_range(_First, _Last)