30 #ifndef _GLIBCXX_DEBUG_UNORDERED_SET
31 #define _GLIBCXX_DEBUG_UNORDERED_SET 1
33 #ifndef __GXX_EXPERIMENTAL_CXX0X__
42 namespace std _GLIBCXX_VISIBILITY(default)
47 template<
typename _Value,
52 :
public _GLIBCXX_STD_C::unordered_set<_Value, _Hash, _Pred, _Alloc>,
56 typedef _GLIBCXX_STD_C::unordered_set<_Value, _Hash,
59 typedef typename _Base::const_iterator _Base_const_iterator;
60 typedef typename _Base::iterator _Base_iterator;
61 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
62 typedef typename _Base::local_iterator _Base_local_iterator;
65 typedef typename _Base::size_type size_type;
66 typedef typename _Base::hasher hasher;
67 typedef typename _Base::key_equal key_equal;
68 typedef typename _Base::allocator_type allocator_type;
70 typedef typename _Base::key_type key_type;
71 typedef typename _Base::value_type value_type;
84 const hasher& __hf = hasher(),
85 const key_equal& __eql = key_equal(),
86 const allocator_type& __a = allocator_type())
87 :
_Base(__n, __hf, __eql, __a) { }
89 template<
typename _InputIterator>
92 const hasher& __hf = hasher(),
93 const key_equal& __eql = key_equal(),
94 const allocator_type& __a = allocator_type())
109 const hasher& __hf = hasher(),
110 const key_equal& __eql = key_equal(),
111 const allocator_type& __a = allocator_type())
112 :
_Base(__l, __n, __hf, __eql, __a) { }
119 *
static_cast<_Base*
>(
this) = __x;
120 this->_M_invalidate_all();
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
190 begin(size_type __b)
const
194 end(size_type __b)
const
198 cbegin(size_type __b)
const
202 cend(size_type __b)
const
205 template<
typename... _Args>
207 emplace(_Args&&... __args)
209 size_type __bucket_count = this->bucket_count();
211 = _Base::emplace(std::forward<_Args>(__args)...);
212 _M_check_rehashed(__bucket_count);
216 template<
typename... _Args>
221 size_type __bucket_count = this->bucket_count();
222 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
223 std::forward<_Args>(__args)...);
224 _M_check_rehashed(__bucket_count);
229 insert(
const value_type& __obj)
231 size_type __bucket_count = this->bucket_count();
233 __pair_type __res = _Base::insert(__obj);
234 _M_check_rehashed(__bucket_count);
242 size_type __bucket_count = this->bucket_count();
243 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
244 _M_check_rehashed(__bucket_count);
249 insert(value_type&& __obj)
251 size_type __bucket_count = this->bucket_count();
253 __pair_type __res = _Base::insert(std::move(__obj));
254 _M_check_rehashed(__bucket_count);
262 size_type __bucket_count = this->bucket_count();
263 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
264 _M_check_rehashed(__bucket_count);
271 size_type __bucket_count = this->bucket_count();
273 _M_check_rehashed(__bucket_count);
276 template<
typename _InputIterator>
278 insert(_InputIterator __first, _InputIterator __last)
280 __glibcxx_check_valid_range(__first, __last);
281 size_type __bucket_count = this->bucket_count();
284 _M_check_rehashed(__bucket_count);
288 find(
const key_type& __key)
289 {
return iterator(_Base::find(__key),
this); }
292 find(
const key_type& __key)
const
296 equal_range(
const key_type& __key)
299 __pair_type __res = _Base::equal_range(__key);
305 equal_range(
const key_type& __key)
const
308 __res = _Base::equal_range(__key);
314 erase(
const key_type& __key)
317 _Base_iterator __victim(_Base::find(__key));
318 if (__victim != _Base::end())
321 [__victim](_Base_const_iterator __it)
322 {
return __it == __victim; });
323 _Base_local_iterator __local_victim = _S_to_local(__victim);
325 [__local_victim](_Base_const_local_iterator __it)
326 {
return __it == __local_victim; });
327 size_type __bucket_count = this->bucket_count();
328 _Base::erase(__victim);
329 _M_check_rehashed(__bucket_count);
339 _Base_const_iterator __victim = __it.
base();
341 [__victim](_Base_const_iterator __it)
342 {
return __it == __victim; });
343 _Base_const_local_iterator __local_victim = _S_to_local(__victim);
345 [__local_victim](_Base_const_local_iterator __it)
346 {
return __it == __local_victim; });
347 size_type __bucket_count = this->bucket_count();
348 _Base_iterator __next = _Base::erase(__it.base());
349 _M_check_rehashed(__bucket_count);
361 for (_Base_const_iterator __tmp = __first.
base();
362 __tmp != __last.
base(); ++__tmp)
364 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
365 _M_message(__gnu_debug::__msg_valid_range)
366 ._M_iterator(__first,
"first")
367 ._M_iterator(__last,
"last"));
369 [__tmp](_Base_const_iterator __it)
370 {
return __it == __tmp; });
371 _Base_const_local_iterator __local_tmp = _S_to_local(__tmp);
373 [__local_tmp](_Base_const_local_iterator __it)
374 {
return __it == __local_tmp; });
376 size_type __bucket_count = this->bucket_count();
377 _Base_iterator __next = _Base::erase(__first.
base(),
379 _M_check_rehashed(__bucket_count);
384 _M_base() noexcept {
return *
this; }
387 _M_base()
const noexcept {
return *
this; }
391 _M_invalidate_locals()
393 _Base_local_iterator __local_end = _Base::end(0);
395 [__local_end](_Base_const_local_iterator __it)
396 {
return __it != __local_end; });
402 _Base_iterator __end = _Base::end();
404 [__end](_Base_const_iterator __it)
405 {
return __it != __end; });
406 _M_invalidate_locals();
410 _M_check_rehashed(size_type __prev_count)
412 if (__prev_count != this->bucket_count())
413 _M_invalidate_locals();
416 static _Base_local_iterator
417 _S_to_local(_Base_iterator __it)
421 return _Base_local_iterator(__it._M_cur, 0, 0);
424 static _Base_const_local_iterator
425 _S_to_local(_Base_const_iterator __it)
429 return _Base_const_local_iterator(__it._M_cur, 0, 0);
433 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
439 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
443 {
return __x._M_equal(__y); }
445 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
447 operator!=(
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
448 const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
449 {
return !(__x == __y); }
453 template<
typename _Value,
458 :
public _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash, _Pred, _Alloc>,
460 unordered_multiset<_Value, _Hash, _Pred, _Alloc> >
462 typedef _GLIBCXX_STD_C::unordered_multiset<_Value, _Hash,
463 _Pred, _Alloc>
_Base;
466 typedef typename _Base::const_iterator _Base_const_iterator;
467 typedef typename _Base::iterator _Base_iterator;
468 typedef typename _Base::const_local_iterator _Base_const_local_iterator;
469 typedef typename _Base::local_iterator _Base_local_iterator;
472 typedef typename _Base::size_type size_type;
473 typedef typename _Base::hasher hasher;
474 typedef typename _Base::key_equal key_equal;
475 typedef typename _Base::allocator_type allocator_type;
477 typedef typename _Base::key_type key_type;
478 typedef typename _Base::value_type value_type;
491 const hasher& __hf = hasher(),
492 const key_equal& __eql = key_equal(),
493 const allocator_type& __a = allocator_type())
494 :
_Base(__n, __hf, __eql, __a) { }
496 template<
typename _InputIterator>
499 const hasher& __hf = hasher(),
500 const key_equal& __eql = key_equal(),
501 const allocator_type& __a = allocator_type())
505 __hf, __eql, __a) { }
516 const hasher& __hf = hasher(),
517 const key_equal& __eql = key_equal(),
518 const allocator_type& __a = allocator_type())
519 :
_Base(__l, __n, __hf, __eql, __a) { }
526 *
static_cast<_Base*
>(
this) = __x;
527 this->_M_invalidate_all();
560 this->_M_invalidate_all();
565 {
return iterator(_Base::begin(),
this); }
568 begin()
const noexcept
573 {
return iterator(_Base::end(),
this); }
580 cbegin()
const noexcept
584 cend()
const noexcept
597 begin(size_type __b)
const
601 end(size_type __b)
const
605 cbegin(size_type __b)
const
609 cend(size_type __b)
const
612 template<
typename... _Args>
614 emplace(_Args&&... __args)
616 size_type __bucket_count = this->bucket_count();
618 = _Base::emplace(std::forward<_Args>(__args)...);
619 _M_check_rehashed(__bucket_count);
623 template<
typename... _Args>
628 size_type __bucket_count = this->bucket_count();
629 _Base_iterator __it = _Base::emplace_hint(__hint.
base(),
630 std::forward<_Args>(__args)...);
631 _M_check_rehashed(__bucket_count);
636 insert(
const value_type& __obj)
638 size_type __bucket_count = this->bucket_count();
639 _Base_iterator __it = _Base::insert(__obj);
640 _M_check_rehashed(__bucket_count);
648 size_type __bucket_count = this->bucket_count();
649 _Base_iterator __it = _Base::insert(__hint.
base(), __obj);
650 _M_check_rehashed(__bucket_count);
655 insert(value_type&& __obj)
657 size_type __bucket_count = this->bucket_count();
658 _Base_iterator __it = _Base::insert(std::move(__obj));
659 _M_check_rehashed(__bucket_count);
667 size_type __bucket_count = this->bucket_count();
668 _Base_iterator __it = _Base::insert(__hint.
base(), std::move(__obj));
669 _M_check_rehashed(__bucket_count);
676 size_type __bucket_count = this->bucket_count();
678 _M_check_rehashed(__bucket_count);
681 template<
typename _InputIterator>
683 insert(_InputIterator __first, _InputIterator __last)
685 __glibcxx_check_valid_range(__first, __last);
686 size_type __bucket_count = this->bucket_count();
689 _M_check_rehashed(__bucket_count);
693 find(
const key_type& __key)
694 {
return iterator(_Base::find(__key),
this); }
697 find(
const key_type& __key)
const
701 equal_range(
const key_type& __key)
704 __pair_type __res = _Base::equal_range(__key);
710 equal_range(
const key_type& __key)
const
713 __res = _Base::equal_range(__key);
719 erase(
const key_type& __key)
723 _Base::equal_range(__key);
724 for (_Base_iterator __victim = __pair.
first; __victim != __pair.
second;)
727 {
return __it == __victim; });
728 _Base_local_iterator __local_victim = _S_to_local(__victim);
730 [__local_victim](_Base_const_local_iterator __it)
731 {
return __it == __local_victim; });
732 _Base::erase(__victim++);
742 _Base_const_iterator __victim = __it.
base();
744 {
return __it == __victim; });
745 _Base_const_local_iterator __local_victim = _S_to_local(__victim);
747 [__local_victim](_Base_const_local_iterator __it)
748 {
return __it == __local_victim; });
749 return iterator(_Base::erase(__it.base()),
this);
760 for (_Base_const_iterator __tmp = __first.
base();
761 __tmp != __last.
base(); ++__tmp)
763 _GLIBCXX_DEBUG_VERIFY(__tmp != _Base::end(),
764 _M_message(__gnu_debug::__msg_valid_range)
765 ._M_iterator(__first,
"first")
766 ._M_iterator(__last,
"last"));
768 {
return __it == __tmp; });
769 _Base_const_local_iterator __local_tmp = _S_to_local(__tmp);
771 [__local_tmp](_Base_const_local_iterator __it)
772 {
return __it == __local_tmp; });
775 __last.
base()),
this);
779 _M_base() noexcept {
return *
this; }
782 _M_base()
const noexcept {
return *
this; }
786 _M_invalidate_locals()
788 _Base_local_iterator __local_end = _Base::end(0);
790 [__local_end](_Base_const_local_iterator __it)
791 {
return __it != __local_end; });
797 _Base_iterator __end = _Base::end();
799 {
return __it != __end; });
800 _M_invalidate_locals();
804 _M_check_rehashed(size_type __prev_count)
806 if (__prev_count != this->bucket_count())
807 _M_invalidate_locals();
810 static _Base_local_iterator
811 _S_to_local(_Base_iterator __it)
815 return _Base_local_iterator(__it._M_cur, 0, 0);
818 static _Base_const_local_iterator
819 _S_to_local(_Base_const_iterator __it)
823 return _Base_const_local_iterator(__it._M_cur, 0, 0);
827 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
833 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
837 {
return __x._M_equal(__y); }
839 template<
typename _Value,
typename _Hash,
typename _Pred,
typename _Alloc>
841 operator!=(
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
842 const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
843 {
return !(__x == __y); }
848 #endif // __GXX_EXPERIMENTAL_CXX0X__
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
_T1 first
second_type is the second bound type
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
The standard allocator, as per [20.4].
#define __glibcxx_check_erase_range(_First, _Last)
void _M_invalidate_local_if(_Predicate __pred)
_Iterator base() const
Return the underlying iterator.
#define __glibcxx_check_erase(_Position)
One of the comparison functors.
void _M_invalidate_if(_Predicate __pred)
A standard container composed of unique keys (containing at most one of each key value) in which the ...
void _M_swap(_Safe_unordered_container_base &__x)
Base class that supports tracking of iterators that reference a sequence.
Class std::unordered_set with safety/checking/debug instrumentation.
A standard container composed of equivalent keys (possibly containing multiple of each key value) in ...
#define __glibcxx_check_insert(_Position)
Struct holding two objects of arbitrary type.
Class std::unordered_multiset with safety/checking/debug instrumentation.
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.
Primary class template hash.