Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/__node_handle is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___NODE_HANDLE
0011 #define _LIBCPP___NODE_HANDLE
0012 
0013 /*
0014 
0015 template<unspecified>
0016 class node-handle {
0017 public:
0018   using value_type     = see below;     // not present for map containers
0019   using key_type       = see below;     // not present for set containers
0020   using mapped_type    = see below;     // not present for set containers
0021   using allocator_type = see below;
0022 
0023 private:
0024   using container_node_type = unspecified;                  // exposition only
0025   using ator_traits = allocator_traits<allocator_type>;     // exposition only
0026 
0027   typename ator_traits::template
0028     rebind_traits<container_node_type>::pointer ptr_;       // exposition only
0029   optional<allocator_type> alloc_;                          // exposition only
0030 
0031 public:
0032   // [container.node.cons], constructors, copy, and assignment
0033   constexpr node-handle() noexcept : ptr_(), alloc_() {}
0034   node-handle(node-handle&&) noexcept;
0035   node-handle& operator=(node-handle&&);
0036 
0037   // [container.node.dtor], destructor
0038   ~node-handle();
0039 
0040   // [container.node.observers], observers
0041   value_type& value() const;            // not present for map containers
0042   key_type& key() const;                // not present for set containers
0043   mapped_type& mapped() const;          // not present for set containers
0044 
0045   allocator_type get_allocator() const;
0046   explicit operator bool() const noexcept;
0047   [[nodiscard]] bool empty() const noexcept; // nodiscard since C++20
0048 
0049   // [container.node.modifiers], modifiers
0050   void swap(node-handle&)
0051     noexcept(ator_traits::propagate_on_container_swap::value ||
0052              ator_traits::is_always_equal::value);
0053 
0054   friend void swap(node-handle& x, node-handle& y) noexcept(noexcept(x.swap(y))) {
0055     x.swap(y);
0056   }
0057 };
0058 
0059 */
0060 
0061 #include <__assert>
0062 #include <__config>
0063 #include <__memory/allocator_traits.h>
0064 #include <__memory/pointer_traits.h>
0065 #include <optional>
0066 
0067 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0068 #  pragma GCC system_header
0069 #endif
0070 
0071 _LIBCPP_PUSH_MACROS
0072 #include <__undef_macros>
0073 
0074 _LIBCPP_BEGIN_NAMESPACE_STD
0075 
0076 #if _LIBCPP_STD_VER >= 17
0077 
0078 // Specialized in __tree & __hash_table for their _NodeType.
0079 template <class _NodeType, class _Alloc>
0080 struct __generic_container_node_destructor;
0081 
0082 template <class _NodeType, class _Alloc, template <class, class> class _MapOrSetSpecifics>
0083 class _LIBCPP_TEMPLATE_VIS __basic_node_handle
0084     : public _MapOrSetSpecifics< _NodeType, __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>> {
0085   template <class _Tp, class _Compare, class _Allocator>
0086   friend class __tree;
0087   template <class _Tp, class _Hash, class _Equal, class _Allocator>
0088   friend class __hash_table;
0089   friend struct _MapOrSetSpecifics< _NodeType, __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>>;
0090 
0091   typedef allocator_traits<_Alloc> __alloc_traits;
0092   typedef __rebind_pointer_t<typename __alloc_traits::void_pointer, _NodeType> __node_pointer_type;
0093 
0094 public:
0095   typedef _Alloc allocator_type;
0096 
0097 private:
0098   __node_pointer_type __ptr_ = nullptr;
0099   optional<allocator_type> __alloc_;
0100 
0101   _LIBCPP_HIDE_FROM_ABI void __release_ptr() {
0102     __ptr_   = nullptr;
0103     __alloc_ = std::nullopt;
0104   }
0105 
0106   _LIBCPP_HIDE_FROM_ABI void __destroy_node_pointer() {
0107     if (__ptr_ != nullptr) {
0108       typedef typename __allocator_traits_rebind< allocator_type, _NodeType>::type __node_alloc_type;
0109       __node_alloc_type __alloc(*__alloc_);
0110       __generic_container_node_destructor<_NodeType, __node_alloc_type>(__alloc, true)(__ptr_);
0111       __ptr_ = nullptr;
0112     }
0113   }
0114 
0115   _LIBCPP_HIDE_FROM_ABI __basic_node_handle(__node_pointer_type __ptr, allocator_type const& __alloc)
0116       : __ptr_(__ptr), __alloc_(__alloc) {}
0117 
0118 public:
0119   _LIBCPP_HIDE_FROM_ABI __basic_node_handle() = default;
0120 
0121   _LIBCPP_HIDE_FROM_ABI __basic_node_handle(__basic_node_handle&& __other) noexcept
0122       : __ptr_(__other.__ptr_), __alloc_(std::move(__other.__alloc_)) {
0123     __other.__ptr_   = nullptr;
0124     __other.__alloc_ = std::nullopt;
0125   }
0126 
0127   _LIBCPP_HIDE_FROM_ABI __basic_node_handle& operator=(__basic_node_handle&& __other) {
0128     _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
0129         __alloc_ == std::nullopt || __alloc_traits::propagate_on_container_move_assignment::value ||
0130             __alloc_ == __other.__alloc_,
0131         "node_type with incompatible allocator passed to "
0132         "node_type::operator=(node_type&&)");
0133 
0134     __destroy_node_pointer();
0135     __ptr_ = __other.__ptr_;
0136 
0137     if (__alloc_traits::propagate_on_container_move_assignment::value || __alloc_ == std::nullopt)
0138       __alloc_ = std::move(__other.__alloc_);
0139 
0140     __other.__ptr_   = nullptr;
0141     __other.__alloc_ = std::nullopt;
0142 
0143     return *this;
0144   }
0145 
0146   _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const { return *__alloc_; }
0147 
0148   _LIBCPP_HIDE_FROM_ABI explicit operator bool() const { return __ptr_ != nullptr; }
0149 
0150   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI bool empty() const { return __ptr_ == nullptr; }
0151 
0152   _LIBCPP_HIDE_FROM_ABI void swap(__basic_node_handle& __other) noexcept(
0153       __alloc_traits::propagate_on_container_swap::value || __alloc_traits::is_always_equal::value) {
0154     using std::swap;
0155     swap(__ptr_, __other.__ptr_);
0156     if (__alloc_traits::propagate_on_container_swap::value || __alloc_ == std::nullopt ||
0157         __other.__alloc_ == std::nullopt)
0158       swap(__alloc_, __other.__alloc_);
0159   }
0160 
0161   _LIBCPP_HIDE_FROM_ABI friend void
0162   swap(__basic_node_handle& __a, __basic_node_handle& __b) noexcept(noexcept(__a.swap(__b))) {
0163     __a.swap(__b);
0164   }
0165 
0166   _LIBCPP_HIDE_FROM_ABI ~__basic_node_handle() { __destroy_node_pointer(); }
0167 };
0168 
0169 template <class _NodeType, class _Derived>
0170 struct __set_node_handle_specifics {
0171   typedef typename _NodeType::__node_value_type value_type;
0172 
0173   _LIBCPP_HIDE_FROM_ABI value_type& value() const { return static_cast<_Derived const*>(this)->__ptr_->__get_value(); }
0174 };
0175 
0176 template <class _NodeType, class _Derived>
0177 struct __map_node_handle_specifics {
0178   typedef typename _NodeType::__node_value_type::key_type key_type;
0179   typedef typename _NodeType::__node_value_type::mapped_type mapped_type;
0180 
0181   _LIBCPP_HIDE_FROM_ABI key_type& key() const {
0182     return static_cast<_Derived const*>(this)->__ptr_->__get_value().__ref().first;
0183   }
0184 
0185   _LIBCPP_HIDE_FROM_ABI mapped_type& mapped() const {
0186     return static_cast<_Derived const*>(this)->__ptr_->__get_value().__ref().second;
0187   }
0188 };
0189 
0190 template <class _NodeType, class _Alloc>
0191 using __set_node_handle _LIBCPP_NODEBUG = __basic_node_handle< _NodeType, _Alloc, __set_node_handle_specifics>;
0192 
0193 template <class _NodeType, class _Alloc>
0194 using __map_node_handle _LIBCPP_NODEBUG = __basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>;
0195 
0196 template <class _Iterator, class _NodeType>
0197 struct _LIBCPP_TEMPLATE_VIS __insert_return_type {
0198   _Iterator position;
0199   bool inserted;
0200   _NodeType node;
0201 };
0202 
0203 #endif // _LIBCPP_STD_VER >= 17
0204 
0205 _LIBCPP_END_NAMESPACE_STD
0206 
0207 _LIBCPP_POP_MACROS
0208 
0209 #endif // _LIBCPP___NODE_HANDLE