35#pragma GCC system_header
40#ifdef __glibcxx_node_extract
46namespace std _GLIBCXX_VISIBILITY(default)
48_GLIBCXX_BEGIN_NAMESPACE_VERSION
66 template<
typename _Val,
typename _NodeAlloc>
67 class _Node_handle_common
69 using _AllocTraits = allocator_traits<_NodeAlloc>;
72 using allocator_type = __alloc_rebind<_NodeAlloc, _Val>;
75 get_allocator() const noexcept
77 __glibcxx_assert(!this->
empty());
78 return allocator_type(_M_alloc._M_alloc);
81 explicit operator bool() const noexcept {
return _M_ptr !=
nullptr; }
83 [[nodiscard]]
bool empty() const noexcept {
return _M_ptr ==
nullptr; }
87 constexpr _Node_handle_common() noexcept : _M_ptr() { }
89 ~_Node_handle_common()
95 _Node_handle_common(_Node_handle_common&& __nh) noexcept
103 operator=(_Node_handle_common&& __nh)
noexcept
110 else if (__nh.empty())
115 _AllocTraits::destroy(*_M_alloc, _M_ptr->_M_valptr());
116 _AllocTraits::deallocate(*_M_alloc, _M_ptr, 1);
118 _M_alloc = __nh._M_alloc.release();
119 _M_ptr = __nh._M_ptr;
120 __nh._M_ptr =
nullptr;
125 _Node_handle_common(
typename _AllocTraits::pointer __ptr,
126 const _NodeAlloc& __alloc)
127 : _M_ptr(__ptr), _M_alloc(__alloc)
129 __glibcxx_assert(__ptr !=
nullptr);
133 _M_swap(_Node_handle_common& __nh)
noexcept
140 else if (__nh.empty())
145 swap(_M_ptr, __nh._M_ptr);
146 _M_alloc.swap(__nh._M_alloc);
155 _M_move(_Node_handle_common&& __nh)
noexcept
158 _M_ptr = __nh._M_ptr;
159 __nh._M_ptr =
nullptr;
168 _NodeAlloc __alloc = _M_alloc.release();
169 _AllocTraits::destroy(__alloc, _M_ptr->_M_valptr());
170 _AllocTraits::deallocate(__alloc, _M_ptr, 1);
185 typename _AllocTraits::pointer _M_ptr;
190 union _Optional_alloc
192 _Optional_alloc() { }
193 ~_Optional_alloc() { }
195 _Optional_alloc(_Optional_alloc&&) =
delete;
196 _Optional_alloc& operator=(_Optional_alloc&&) =
delete;
198 _Optional_alloc(
const _NodeAlloc& __alloc) noexcept
204 operator=(_NodeAlloc&& __alloc)
noexcept
206 using _ATr = _AllocTraits;
207 if constexpr (_ATr::propagate_on_container_move_assignment::value)
209 else if constexpr (!_AllocTraits::is_always_equal::value)
210 __glibcxx_assert(_M_alloc == __alloc);
215 swap(_Optional_alloc& __other)
noexcept
218 if constexpr (_AllocTraits::propagate_on_container_swap::value)
219 swap(_M_alloc, __other._M_alloc);
220 else if constexpr (!_AllocTraits::is_always_equal::value)
221 __glibcxx_assert(_M_alloc == __other._M_alloc);
225 _NodeAlloc&
operator*() noexcept {
return _M_alloc; }
228 _NodeAlloc release() noexcept
231 _M_alloc.~_NodeAlloc();
235 [[__no_unique_address__]] _NodeAlloc _M_alloc;
238 [[__no_unique_address__]] _Optional_alloc _M_alloc;
240 template<
typename _Key2,
typename _Value2,
typename _KeyOfValue,
241 typename _Compare,
typename _ValueAlloc>
242 friend class _Rb_tree;
244 template<
typename _Key2,
typename _Value2,
typename _ValueAlloc,
245 typename _ExtractKey,
typename _Equal,
246 typename _Hash,
typename _RangeHash,
typename _Unused,
247 typename _RehashPolicy,
typename _Traits>
248 friend class _Hashtable;
254 template<
typename _Key,
typename _Value,
typename _NodeAlloc>
255 class _Node_handle :
public _Node_handle_common<_Value, _NodeAlloc>
258 constexpr _Node_handle() noexcept = default;
259 ~_Node_handle() = default;
260 _Node_handle(_Node_handle&&) noexcept = default;
263 operator=(_Node_handle&&) noexcept = default;
265 using key_type = _Key;
266 using mapped_type = typename _Value::second_type;
271 __glibcxx_assert(!this->
empty());
276 mapped() const noexcept
278 __glibcxx_assert(!this->
empty());
283 swap(_Node_handle& __nh)
noexcept
287 swap(_M_pkey, __nh._M_pkey);
288 swap(_M_pmapped, __nh._M_pmapped);
292 swap(_Node_handle& __x, _Node_handle& __y)
293 noexcept(
noexcept(__x.swap(__y)))
297 using _AllocTraits = allocator_traits<_NodeAlloc>;
299 _Node_handle(
typename _AllocTraits::pointer __ptr,
300 const _NodeAlloc& __alloc)
301 : _Node_handle_common<_Value, _NodeAlloc>(__ptr, __alloc)
305 auto& __key =
const_cast<_Key&
>(__ptr->_M_valptr()->first);
306 _M_pkey = _S_pointer_to(__key);
307 _M_pmapped = _S_pointer_to(__ptr->_M_valptr()->second);
312 _M_pmapped =
nullptr;
316 template<
typename _Tp>
319 remove_reference_t<_Tp>>;
321 __pointer<_Key> _M_pkey =
nullptr;
322 __pointer<typename _Value::second_type> _M_pmapped =
nullptr;
324 template<
typename _Tp>
326 _S_pointer_to(_Tp& __obj)
327 {
return pointer_traits<__pointer<_Tp>>::pointer_to(__obj); }
330 _M_key() const noexcept {
return key(); }
332 template<
typename _Key2,
typename _Value2,
typename _KeyOfValue,
333 typename _Compare,
typename _ValueAlloc>
334 friend class _Rb_tree;
336 template<
typename _Key2,
typename _Value2,
typename _ValueAlloc,
337 typename _ExtractKey,
typename _Equal,
338 typename _Hash,
typename _RangeHash,
typename _Unused,
339 typename _RehashPolicy,
typename _Traits>
340 friend class _Hashtable;
344 template<
typename _Value,
typename _NodeAlloc>
345 class _Node_handle<_Value, _Value, _NodeAlloc>
346 :
public _Node_handle_common<_Value, _NodeAlloc>
349 constexpr _Node_handle() noexcept = default;
350 ~_Node_handle() = default;
351 _Node_handle(_Node_handle&&) noexcept = default;
354 operator=(_Node_handle&&) noexcept = default;
356 using value_type = _Value;
359 value() const noexcept
361 __glibcxx_assert(!this->
empty());
362 return *this->_M_ptr->_M_valptr();
366 swap(_Node_handle& __nh)
noexcept
367 { this->_M_swap(__nh); }
370 swap(_Node_handle& __x, _Node_handle& __y)
371 noexcept(
noexcept(__x.swap(__y)))
375 using _AllocTraits = allocator_traits<_NodeAlloc>;
377 _Node_handle(
typename _AllocTraits::pointer __ptr,
378 const _NodeAlloc& __alloc)
379 : _Node_handle_common<_Value, _NodeAlloc>(__ptr, __alloc) { }
382 _M_key() const noexcept {
return value(); }
384 template<
typename _Key,
typename _Val,
typename _KeyOfValue,
385 typename _Compare,
typename _Alloc>
386 friend class _Rb_tree;
388 template<
typename _Key2,
typename _Value2,
typename _ValueAlloc,
389 typename _ExtractKey,
typename _Equal,
390 typename _Hash,
typename _RangeHash,
typename _Unused,
391 typename _RehashPolicy,
typename _Traits>
392 friend class _Hashtable;
396 template<
typename _Iterator,
typename _NodeHandle>
397 struct _Node_insert_return
399 _Iterator position = _Iterator();
400 bool inserted =
false;
406_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.