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;
64 typedef typename _Base::size_type size_type;
65 typedef typename _Base::hasher hasher;
66 typedef typename _Base::key_equal key_equal;
67 typedef typename _Base::allocator_type allocator_type;
69 typedef typename _Base::key_type key_type;
70 typedef typename _Base::value_type value_type;
83 const hasher& __hf = hasher(),
84 const key_equal& __eql = key_equal(),
85 const allocator_type& __a = allocator_type())
86 :
_Base(__n, __hf, __eql, __a) { }
88 template<
typename _InputIterator>
91 const hasher& __hf = hasher(),
92 const key_equal& __eql = key_equal(),
93 const allocator_type& __a = allocator_type())
108 const hasher& __hf = hasher(),
109 const key_equal& __eql = key_equal(),
110 const allocator_type& __a = allocator_type())
111 :
_Base(__l, __n, __hf, __eql, __a) { }
118 *
static_cast<_Base*
>(
this) = __x;
119 this->_M_invalidate_all();
128 __glibcxx_check_self_move_assign(__x);
153 this->_M_invalidate_all();
158 {
return iterator(_Base::begin(),
this); }
161 begin()
const noexcept
166 {
return iterator(_Base::end(),
this); }
173 cbegin()
const noexcept
177 cend()
const noexcept
184 __glibcxx_check_bucket_index(__b);
191 __glibcxx_check_bucket_index(__b);
196 begin(size_type __b)
const
198 __glibcxx_check_bucket_index(__b);
203 end(size_type __b)
const
205 __glibcxx_check_bucket_index(__b);
210 cbegin(size_type __b)
const
212 __glibcxx_check_bucket_index(__b);
217 cend(size_type __b)
const
219 __glibcxx_check_bucket_index(__b);
224 bucket_size(size_type __b)
const
226 __glibcxx_check_bucket_index(__b);
227 return _Base::bucket_size(__b);
231 max_load_factor()
const noexcept
232 {
return _Base::max_load_factor(); }
235 max_load_factor(
float __f)
237 __glibcxx_check_max_load_factor(__f);
238 _Base::max_load_factor(__f);
241 template<
typename... _Args>
243 emplace(_Args&&... __args)
245 size_type __bucket_count = this->bucket_count();
247 = _Base::emplace(std::forward<_Args>(__args)...);
248 _M_check_rehashed(__bucket_count);
252 template<
typename... _Args>
257 size_type __bucket_count = this->bucket_count();
258 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
259 std::forward<_Args>(__args)...);
260 _M_check_rehashed(__bucket_count);
265 insert(
const value_type& __obj)
267 size_type __bucket_count = this->bucket_count();
269 __pair_type __res = _Base::insert(__obj);
270 _M_check_rehashed(__bucket_count);
278 size_type __bucket_count = this->bucket_count();
279 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
280 _M_check_rehashed(__bucket_count);
285 insert(value_type&& __obj)
287 size_type __bucket_count = this->bucket_count();
289 __pair_type __res = _Base::insert(std::move(__obj));
290 _M_check_rehashed(__bucket_count);
298 size_type __bucket_count = this->bucket_count();
299 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
300 _M_check_rehashed(__bucket_count);
307 size_type __bucket_count = this->bucket_count();
309 _M_check_rehashed(__bucket_count);
312 template<
typename _InputIterator>
314 insert(_InputIterator __first, _InputIterator __last)
316 __glibcxx_check_valid_range(__first, __last);
317 size_type __bucket_count = this->bucket_count();
320 _M_check_rehashed(__bucket_count);
324 find(
const key_type& __key)
325 {
return iterator(_Base::find(__key),
this); }
328 find(
const key_type& __key)
const
332 equal_range(
const key_type& __key)
335 __pair_type __res = _Base::equal_range(__key);
341 equal_range(
const key_type& __key)
const
344 __res = _Base::equal_range(__key);
350 erase(
const key_type& __key)
353 _Base_iterator __victim(_Base::find(__key));
354 if (__victim != _Base::end())
357 [__victim](_Base_const_iterator __it)
358 {
return __it == __victim; });
360 [__victim](_Base_const_local_iterator __it)
361 {
return __it._M_cur == __victim._M_cur; });
362 size_type __bucket_count = this->bucket_count();
363 _Base::erase(__victim);
364 _M_check_rehashed(__bucket_count);
374 _Base_const_iterator __victim = __it.
base();
376 [__victim](_Base_const_iterator __it)
377 {
return __it == __victim; });
379 [__victim](_Base_const_local_iterator __it)
380 {
return __it._M_cur == __victim._M_cur; });
381 size_type __bucket_count = this->bucket_count();
382 _Base_iterator __next = _Base::erase(__it.base());
383 _M_check_rehashed(__bucket_count);
395 for (_Base_const_iterator __tmp = __first.
base();
396 __tmp != __last.
base(); ++__tmp)
398 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
399 _M_message(__gnu_debug::__msg_valid_range)
400 ._M_iterator(__first,
"first")
401 ._M_iterator(__last,
"last"));
403 [__tmp](_Base_const_iterator __it)
404 {
return __it == __tmp; });
406 [__tmp](_Base_const_local_iterator __it)
407 {
return __it._M_cur == __tmp._M_cur; });
409 size_type __bucket_count = this->bucket_count();
410 _Base_iterator __next = _Base::erase(__first.
base(),
412 _M_check_rehashed(__bucket_count);
417 _M_base() noexcept {
return *
this; }
420 _M_base()
const noexcept {
return *
this; }
424 _M_invalidate_locals()
426 _Base_local_iterator __local_end = _Base::end(0);
428 [__local_end](_Base_const_local_iterator __it)
429 {
return __it != __local_end; });
435 _Base_iterator __end = _Base::end();
437 [__end](_Base_const_iterator __it)
438 {
return __it != __end; });
439 _M_invalidate_locals();
443 _M_check_rehashed(size_type __prev_count)
445 if (__prev_count != this->bucket_count())
446 _M_invalidate_locals();
450 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
456 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
460 {
return __x._M_base() == __y._M_base(); }
462 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
464 operator!=(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
465 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
466 {
return !(__x == __y); }
470 template<
typename _Value,
475 :
public _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash, _Pred, _Alloc>,
477 unordered_multiset<_Value, _Hash, _Pred, _Alloc> >
479 typedef _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash,
480 _Pred, _Alloc>
_Base;
483 typedef typename _Base::const_iterator _Base_const_iterator;
484 typedef typename _Base::iterator _Base_iterator;
485 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
486 typedef typename _Base::local_iterator _Base_local_iterator;
489 typedef typename _Base::size_type size_type;
490 typedef typename _Base::hasher hasher;
491 typedef typename _Base::key_equal key_equal;
492 typedef typename _Base::allocator_type allocator_type;
494 typedef typename _Base::key_type key_type;
495 typedef typename _Base::value_type value_type;
508 const hasher& __hf = hasher(),
509 const key_equal& __eql = key_equal(),
510 const allocator_type& __a = allocator_type())
511 :
_Base(__n, __hf, __eql, __a) { }
513 template<
typename _InputIterator>
516 const hasher& __hf = hasher(),
517 const key_equal& __eql = key_equal(),
518 const allocator_type& __a = allocator_type())
522 __hf, __eql, __a) { }
533 const hasher& __hf = hasher(),
534 const key_equal& __eql = key_equal(),
535 const allocator_type& __a = allocator_type())
536 :
_Base(__l, __n, __hf, __eql, __a) { }
543 *
static_cast<_Base*
>(
this) = __x;
544 this->_M_invalidate_all();
553 __glibcxx_check_self_move_assign(__x);
578 this->_M_invalidate_all();
583 {
return iterator(_Base::begin(),
this); }
586 begin()
const noexcept
591 {
return iterator(_Base::end(),
this); }
598 cbegin()
const noexcept
602 cend()
const noexcept
609 __glibcxx_check_bucket_index(__b);
616 __glibcxx_check_bucket_index(__b);
621 begin(size_type __b)
const
623 __glibcxx_check_bucket_index(__b);
628 end(size_type __b)
const
630 __glibcxx_check_bucket_index(__b);
635 cbegin(size_type __b)
const
637 __glibcxx_check_bucket_index(__b);
642 cend(size_type __b)
const
644 __glibcxx_check_bucket_index(__b);
649 bucket_size(size_type __b)
const
651 __glibcxx_check_bucket_index(__b);
652 return _Base::bucket_size(__b);
656 max_load_factor()
const noexcept
657 {
return _Base::max_load_factor(); }
660 max_load_factor(
float __f)
662 __glibcxx_check_max_load_factor(__f);
663 _Base::max_load_factor(__f);
666 template<
typename... _Args>
668 emplace(_Args&&... __args)
670 size_type __bucket_count = this->bucket_count();
672 = _Base::emplace(std::forward<_Args>(__args)...);
673 _M_check_rehashed(__bucket_count);
677 template<
typename... _Args>
682 size_type __bucket_count = this->bucket_count();
683 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
684 std::forward<_Args>(__args)...);
685 _M_check_rehashed(__bucket_count);
690 insert(
const value_type& __obj)
692 size_type __bucket_count = this->bucket_count();
693 _Base_iterator __it = _Base::insert(__obj);
694 _M_check_rehashed(__bucket_count);
702 size_type __bucket_count = this->bucket_count();
703 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
704 _M_check_rehashed(__bucket_count);
709 insert(value_type&& __obj)
711 size_type __bucket_count = this->bucket_count();
712 _Base_iterator __it = _Base::insert(std::move(__obj));
713 _M_check_rehashed(__bucket_count);
721 size_type __bucket_count = this->bucket_count();
722 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
723 _M_check_rehashed(__bucket_count);
730 size_type __bucket_count = this->bucket_count();
732 _M_check_rehashed(__bucket_count);
735 template<
typename _InputIterator>
737 insert(_InputIterator __first, _InputIterator __last)
739 __glibcxx_check_valid_range(__first, __last);
740 size_type __bucket_count = this->bucket_count();
743 _M_check_rehashed(__bucket_count);
747 find(
const key_type& __key)
748 {
return iterator(_Base::find(__key),
this); }
751 find(
const key_type& __key)
const
755 equal_range(
const key_type& __key)
758 __pair_type __res = _Base::equal_range(__key);
764 equal_range(
const key_type& __key)
const
767 __res = _Base::equal_range(__key);
773 erase(
const key_type& __key)
777 _Base::equal_range(__key);
778 for (_Base_iterator __victim = __pair.
first; __victim != __pair.
second;)
781 {
return __it == __victim; });
783 [__victim](_Base_const_local_iterator __it)
784 {
return __it._M_cur == __victim._M_cur; });
785 _Base::erase(__victim++);
795 _Base_const_iterator __victim = __it.
base();
797 {
return __it == __victim; });
799 [__victim](_Base_const_local_iterator __it)
800 {
return __it._M_cur == __victim._M_cur; });
801 return iterator(_Base::erase(__it.base()),
this);
812 for (_Base_const_iterator __tmp = __first.
base();
813 __tmp != __last.
base(); ++__tmp)
815 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
816 _M_message(__gnu_debug::__msg_valid_range)
817 ._M_iterator(__first,
"first")
818 ._M_iterator(__last,
"last"));
820 {
return __it == __tmp; });
822 [__tmp](_Base_const_local_iterator __it)
823 {
return __it._M_cur == __tmp._M_cur; });
826 __last.
base()),
this);
830 _M_base() noexcept {
return *
this; }
833 _M_base()
const noexcept {
return *
this; }
837 _M_invalidate_locals()
839 _Base_local_iterator __local_end = _Base::end(0);
841 [__local_end](_Base_const_local_iterator __it)
842 {
return __it != __local_end; });
848 _Base_iterator __end = _Base::end();
850 {
return __it != __end; });
851 _M_invalidate_locals();
855 _M_check_rehashed(size_type __prev_count)
857 if (__prev_count != this->bucket_count())
858 _M_invalidate_locals();
862 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
868 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
872 {
return __x._M_base() == __y._M_base(); }
874 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
876 operator!=(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
877 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
878 {
return !(__x == __y); }
A standard container composed of equivalent keys (possibly containing multiple of each key value) in ...
_T1 first
second_type is the second bound type
Base class for constructing a safe unordered container type that tracks iterators that reference it...
Class std::unordered_set with safety/checking/debug instrumentation.
void _M_invalidate_local_if(_Predicate __pred)
_Iterator base() const
Return the underlying iterator.
void _M_invalidate_if(_Predicate __pred)
void _M_swap(_Safe_unordered_container_base &__x)
Primary class template hash.
Struct holding two objects of arbitrary type.
#define __glibcxx_check_insert(_Position)
Base class that supports tracking of iterators that reference a sequence.
Class std::unordered_multiset with safety/checking/debug instrumentation.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
One of the comparison functors.
A standard container composed of unique keys (containing at most one of each key value) in which the ...
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.
_T2 second
first is a copy of the first object
The standard allocator, as per [20.4].
#define __glibcxx_check_erase(_Position)
void swap(function< _Res(_Args...)> &__x, function< _Res(_Args...)> &__y)
Swap the targets of two polymorphic function object wrappers.
#define __glibcxx_check_erase_range(_First, _Last)