34#pragma GCC system_header
38#ifdef __glibcxx_node_extract
44namespace std _GLIBCXX_VISIBILITY(default)
46_GLIBCXX_BEGIN_NAMESPACE_VERSION
64 template<
typename _Val,
typename _NodeAlloc>
65 class _Node_handle_common
67 using _AllocTraits = allocator_traits<_NodeAlloc>;
70 using allocator_type = __alloc_rebind<_NodeAlloc, _Val>;
73 get_allocator() const noexcept
75 __glibcxx_assert(!this->
empty());
76 return allocator_type(_M_alloc._M_alloc);
79 explicit operator bool() const noexcept {
return _M_ptr !=
nullptr; }
81 [[nodiscard]]
bool empty() const noexcept {
return _M_ptr ==
nullptr; }
85 constexpr _Node_handle_common() noexcept : _M_ptr() { }
87 ~_Node_handle_common()
93 _Node_handle_common(_Node_handle_common&& __nh) noexcept
101 operator=(_Node_handle_common&& __nh)
noexcept
108 else if (__nh.empty())
113 _AllocTraits::destroy(*_M_alloc, _M_ptr->_M_valptr());
114 _AllocTraits::deallocate(*_M_alloc, _M_ptr, 1);
116 _M_alloc = __nh._M_alloc.release();
117 _M_ptr = __nh._M_ptr;
118 __nh._M_ptr =
nullptr;
123 _Node_handle_common(
typename _AllocTraits::pointer __ptr,
124 const _NodeAlloc& __alloc)
125 : _M_ptr(__ptr), _M_alloc(__alloc)
127 __glibcxx_assert(__ptr !=
nullptr);
131 _M_swap(_Node_handle_common& __nh)
noexcept
138 else if (__nh.empty())
143 swap(_M_ptr, __nh._M_ptr);
144 _M_alloc.swap(__nh._M_alloc);
153 _M_move(_Node_handle_common&& __nh)
noexcept
156 _M_ptr = __nh._M_ptr;
157 __nh._M_ptr =
nullptr;
166 _NodeAlloc __alloc = _M_alloc.release();
167 _AllocTraits::destroy(__alloc, _M_ptr->_M_valptr());
168 _AllocTraits::deallocate(__alloc, _M_ptr, 1);
183 typename _AllocTraits::pointer _M_ptr;
188 union _Optional_alloc
190 _Optional_alloc() { }
191 ~_Optional_alloc() { }
193 _Optional_alloc(_Optional_alloc&&) =
delete;
194 _Optional_alloc& operator=(_Optional_alloc&&) =
delete;
196 _Optional_alloc(
const _NodeAlloc& __alloc) noexcept
202 operator=(_NodeAlloc&& __alloc)
noexcept
204 using _ATr = _AllocTraits;
205 if constexpr (_ATr::propagate_on_container_move_assignment::value)
207 else if constexpr (!_AllocTraits::is_always_equal::value)
208 __glibcxx_assert(_M_alloc == __alloc);
213 swap(_Optional_alloc& __other)
noexcept
216 if constexpr (_AllocTraits::propagate_on_container_swap::value)
217 swap(_M_alloc, __other._M_alloc);
218 else if constexpr (!_AllocTraits::is_always_equal::value)
219 __glibcxx_assert(_M_alloc == __other._M_alloc);
223 _NodeAlloc&
operator*() noexcept {
return _M_alloc; }
226 _NodeAlloc release() noexcept
229 _M_alloc.~_NodeAlloc();
233 [[__no_unique_address__]] _NodeAlloc _M_alloc;
236 [[__no_unique_address__]] _Optional_alloc _M_alloc;
238 template<
typename _Key2,
typename _Value2,
typename _KeyOfValue,
239 typename _Compare,
typename _ValueAlloc>
240 friend class _Rb_tree;
242 template<
typename _Key2,
typename _Value2,
typename _ValueAlloc,
243 typename _ExtractKey,
typename _Equal,
244 typename _Hash,
typename _RangeHash,
typename _Unused,
245 typename _RehashPolicy,
typename _Traits>
246 friend class _Hashtable;
252 template<
typename _Key,
typename _Value,
typename _NodeAlloc>
253 class _Node_handle :
public _Node_handle_common<_Value, _NodeAlloc>
256 constexpr _Node_handle() noexcept = default;
257 ~_Node_handle() = default;
258 _Node_handle(_Node_handle&&) noexcept = default;
261 operator=(_Node_handle&&) noexcept = default;
263 using key_type = _Key;
264 using mapped_type = typename _Value::second_type;
269 __glibcxx_assert(!this->
empty());
274 mapped() const noexcept
276 __glibcxx_assert(!this->
empty());
281 swap(_Node_handle& __nh)
noexcept
285 swap(_M_pkey, __nh._M_pkey);
286 swap(_M_pmapped, __nh._M_pmapped);
290 swap(_Node_handle& __x, _Node_handle& __y)
291 noexcept(
noexcept(__x.swap(__y)))
295 using _AllocTraits = allocator_traits<_NodeAlloc>;
297 _Node_handle(
typename _AllocTraits::pointer __ptr,
298 const _NodeAlloc& __alloc)
299 : _Node_handle_common<_Value, _NodeAlloc>(__ptr, __alloc)
303 auto& __key =
const_cast<_Key&
>(__ptr->_M_valptr()->first);
304 _M_pkey = _S_pointer_to(__key);
305 _M_pmapped = _S_pointer_to(__ptr->_M_valptr()->second);
310 _M_pmapped =
nullptr;
314 template<
typename _Tp>
317 remove_reference_t<_Tp>>;
319 __pointer<_Key> _M_pkey =
nullptr;
320 __pointer<typename _Value::second_type> _M_pmapped =
nullptr;
322 template<
typename _Tp>
324 _S_pointer_to(_Tp& __obj)
325 {
return pointer_traits<__pointer<_Tp>>::pointer_to(__obj); }
328 _M_key() const noexcept {
return key(); }
330 template<
typename _Key2,
typename _Value2,
typename _KeyOfValue,
331 typename _Compare,
typename _ValueAlloc>
332 friend class _Rb_tree;
334 template<
typename _Key2,
typename _Value2,
typename _ValueAlloc,
335 typename _ExtractKey,
typename _Equal,
336 typename _Hash,
typename _RangeHash,
typename _Unused,
337 typename _RehashPolicy,
typename _Traits>
338 friend class _Hashtable;
342 template<
typename _Value,
typename _NodeAlloc>
343 class _Node_handle<_Value, _Value, _NodeAlloc>
344 :
public _Node_handle_common<_Value, _NodeAlloc>
347 constexpr _Node_handle() noexcept = default;
348 ~_Node_handle() = default;
349 _Node_handle(_Node_handle&&) noexcept = default;
352 operator=(_Node_handle&&) noexcept = default;
354 using value_type = _Value;
357 value() const noexcept
359 __glibcxx_assert(!this->
empty());
360 return *this->_M_ptr->_M_valptr();
364 swap(_Node_handle& __nh)
noexcept
365 { this->_M_swap(__nh); }
368 swap(_Node_handle& __x, _Node_handle& __y)
369 noexcept(
noexcept(__x.swap(__y)))
373 using _AllocTraits = allocator_traits<_NodeAlloc>;
375 _Node_handle(
typename _AllocTraits::pointer __ptr,
376 const _NodeAlloc& __alloc)
377 : _Node_handle_common<_Value, _NodeAlloc>(__ptr, __alloc) { }
380 _M_key() const noexcept {
return value(); }
382 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
383 typename _Compare,
typename _Alloc>
384 friend class _Rb_tree;
386 template<
typename _Key2,
typename _Value2,
typename _ValueAlloc,
387 typename _ExtractKey,
typename _Equal,
388 typename _Hash,
typename _RangeHash,
typename _Unused,
389 typename _RehashPolicy,
typename _Traits>
390 friend class _Hashtable;
394 template<
typename _Iterator,
typename _NodeHandle>
395 struct _Node_insert_return
397 _Iterator position = _Iterator();
398 bool inserted =
false;
404_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
typename pointer_traits< _Ptr >::template rebind< _Tp > __ptr_rebind
Convenience alias for rebinding pointers.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.