// RB tree implementation -*- C++ -*-
-// Copyright (C) 2001-2018 Free Software Foundation, Inc.
+// Copyright (C) 2001-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
typedef __gnu_cxx::__alloc_traits<_Node_allocator> _Alloc_traits;
-#if __cplusplus >= 201103L
- static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
- "comparison object must be invocable with two arguments of key type");
-# if __cplusplus >= 201703L
- // _GLIBCXX_RESOLVE_LIB_DEFECTS
- // 2542. Missing const requirements for associative containers
- static_assert(is_invocable_v<const _Compare&, const _Key&, const _Key&>,
- "comparison object must be invocable as const");
-# endif // C++17
-#endif // C++11
-
protected:
typedef _Rb_tree_node_base* _Base_ptr;
typedef const _Rb_tree_node_base* _Const_Base_ptr;
_M_end() const _GLIBCXX_NOEXCEPT
{ return &this->_M_impl._M_header; }
- static const_reference
- _S_value(_Const_Link_type __x)
- { return *__x->_M_valptr(); }
-
static const _Key&
_S_key(_Const_Link_type __x)
- { return _KeyOfValue()(_S_value(__x)); }
+ {
+#if __cplusplus >= 201103L
+ // If we're asking for the key we're presumably using the comparison
+ // object, and so this is a good place to sanity check it.
+ static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
+ "comparison object must be invocable "
+ "with two arguments of key type");
+# if __cplusplus >= 201703L
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 2542. Missing const requirements for associative containers
+ if constexpr (__is_invocable<_Compare&, const _Key&, const _Key&>{})
+ static_assert(
+ is_invocable_v<const _Compare&, const _Key&, const _Key&>,
+ "comparison object must be invocable as const");
+# endif // C++17
+#endif // C++11
+
+ return _KeyOfValue()(*__x->_M_valptr());
+ }
static _Link_type
_S_left(_Base_ptr __x) _GLIBCXX_NOEXCEPT
_S_right(_Const_Base_ptr __x) _GLIBCXX_NOEXCEPT
{ return static_cast<_Const_Link_type>(__x->_M_right); }
- static const_reference
- _S_value(_Const_Base_ptr __x)
- { return *static_cast<_Const_Link_type>(__x)->_M_valptr(); }
-
static const _Key&
_S_key(_Const_Base_ptr __x)
- { return _KeyOfValue()(_S_value(__x)); }
+ { return _S_key(static_cast<_Const_Link_type>(__x)); }
static _Base_ptr
_S_minimum(_Base_ptr __x) _GLIBCXX_NOEXCEPT
rend() const _GLIBCXX_NOEXCEPT
{ return const_reverse_iterator(begin()); }
- bool
+ _GLIBCXX_NODISCARD bool
empty() const _GLIBCXX_NOEXCEPT
{ return _M_impl._M_node_count == 0; }
_M_erase_aux(__position);
}
#endif
+
size_type
erase(const key_type& __x);
erase(const_iterator __first, const_iterator __last)
{ _M_erase_aux(__first, __last); }
#endif
- void
- erase(const key_type* __first, const key_type* __last);
void
clear() _GLIBCXX_NOEXCEPT
return __old_size - size();
}
- template<typename _Key, typename _Val, typename _KeyOfValue,
- typename _Compare, typename _Alloc>
- void
- _Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::
- erase(const _Key* __first, const _Key* __last)
- {
- while (__first != __last)
- erase(*__first++);
- }
-
template<typename _Key, typename _Val, typename _KeyOfValue,
typename _Compare, typename _Alloc>
typename _Rb_tree<_Key, _Val, _KeyOfValue,