Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:36

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___CXX03___MEMORY_UNIQUE_PTR_H
0011 #define _LIBCPP___CXX03___MEMORY_UNIQUE_PTR_H
0012 
0013 #include <__cxx03/__compare/compare_three_way.h>
0014 #include <__cxx03/__compare/compare_three_way_result.h>
0015 #include <__cxx03/__compare/three_way_comparable.h>
0016 #include <__cxx03/__config>
0017 #include <__cxx03/__functional/hash.h>
0018 #include <__cxx03/__functional/operations.h>
0019 #include <__cxx03/__memory/allocator_traits.h> // __pointer
0020 #include <__cxx03/__memory/auto_ptr.h>
0021 #include <__cxx03/__memory/compressed_pair.h>
0022 #include <__cxx03/__type_traits/add_lvalue_reference.h>
0023 #include <__cxx03/__type_traits/common_type.h>
0024 #include <__cxx03/__type_traits/conditional.h>
0025 #include <__cxx03/__type_traits/dependent_type.h>
0026 #include <__cxx03/__type_traits/integral_constant.h>
0027 #include <__cxx03/__type_traits/is_array.h>
0028 #include <__cxx03/__type_traits/is_assignable.h>
0029 #include <__cxx03/__type_traits/is_constructible.h>
0030 #include <__cxx03/__type_traits/is_convertible.h>
0031 #include <__cxx03/__type_traits/is_function.h>
0032 #include <__cxx03/__type_traits/is_pointer.h>
0033 #include <__cxx03/__type_traits/is_reference.h>
0034 #include <__cxx03/__type_traits/is_same.h>
0035 #include <__cxx03/__type_traits/is_swappable.h>
0036 #include <__cxx03/__type_traits/is_trivially_relocatable.h>
0037 #include <__cxx03/__type_traits/is_void.h>
0038 #include <__cxx03/__type_traits/remove_extent.h>
0039 #include <__cxx03/__type_traits/remove_pointer.h>
0040 #include <__cxx03/__type_traits/type_identity.h>
0041 #include <__cxx03/__utility/declval.h>
0042 #include <__cxx03/__utility/forward.h>
0043 #include <__cxx03/__utility/move.h>
0044 #include <__cxx03/cstddef>
0045 
0046 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0047 #  pragma GCC system_header
0048 #endif
0049 
0050 _LIBCPP_PUSH_MACROS
0051 #include <__cxx03/__undef_macros>
0052 
0053 _LIBCPP_BEGIN_NAMESPACE_STD
0054 
0055 #ifndef _LIBCPP_CXX03_LANG
0056 
0057 template <class _Ptr>
0058 struct __is_noexcept_deref_or_void {
0059   static constexpr bool value = noexcept(*std::declval<_Ptr>());
0060 };
0061 
0062 template <>
0063 struct __is_noexcept_deref_or_void<void*> : true_type {};
0064 #endif
0065 
0066 template <class _Tp>
0067 struct _LIBCPP_TEMPLATE_VIS default_delete {
0068   static_assert(!is_function<_Tp>::value, "default_delete cannot be instantiated for function types");
0069 #ifndef _LIBCPP_CXX03_LANG
0070   _LIBCPP_HIDE_FROM_ABI constexpr default_delete() _NOEXCEPT = default;
0071 #else
0072   _LIBCPP_HIDE_FROM_ABI default_delete() {}
0073 #endif
0074   template <class _Up, __enable_if_t<is_convertible<_Up*, _Tp*>::value, int> = 0>
0075   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 default_delete(const default_delete<_Up>&) _NOEXCEPT {}
0076 
0077   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void operator()(_Tp* __ptr) const _NOEXCEPT {
0078     static_assert(sizeof(_Tp) >= 0, "cannot delete an incomplete type");
0079     static_assert(!is_void<_Tp>::value, "cannot delete an incomplete type");
0080     delete __ptr;
0081   }
0082 };
0083 
0084 template <class _Tp>
0085 struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
0086 private:
0087   template <class _Up>
0088   struct _EnableIfConvertible : enable_if<is_convertible<_Up (*)[], _Tp (*)[]>::value> {};
0089 
0090 public:
0091 #ifndef _LIBCPP_CXX03_LANG
0092   _LIBCPP_HIDE_FROM_ABI constexpr default_delete() _NOEXCEPT = default;
0093 #else
0094   _LIBCPP_HIDE_FROM_ABI default_delete() {}
0095 #endif
0096 
0097   template <class _Up>
0098   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23
0099   default_delete(const default_delete<_Up[]>&, typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
0100 
0101   template <class _Up>
0102   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename _EnableIfConvertible<_Up>::type
0103   operator()(_Up* __ptr) const _NOEXCEPT {
0104     static_assert(sizeof(_Up) >= 0, "cannot delete an incomplete type");
0105     delete[] __ptr;
0106   }
0107 };
0108 
0109 template <class _Deleter>
0110 struct __unique_ptr_deleter_sfinae {
0111   static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
0112   typedef const _Deleter& __lval_ref_type;
0113   typedef _Deleter&& __good_rval_ref_type;
0114   typedef true_type __enable_rval_overload;
0115 };
0116 
0117 template <class _Deleter>
0118 struct __unique_ptr_deleter_sfinae<_Deleter const&> {
0119   typedef const _Deleter& __lval_ref_type;
0120   typedef const _Deleter&& __bad_rval_ref_type;
0121   typedef false_type __enable_rval_overload;
0122 };
0123 
0124 template <class _Deleter>
0125 struct __unique_ptr_deleter_sfinae<_Deleter&> {
0126   typedef _Deleter& __lval_ref_type;
0127   typedef _Deleter&& __bad_rval_ref_type;
0128   typedef false_type __enable_rval_overload;
0129 };
0130 
0131 #if defined(_LIBCPP_ABI_ENABLE_UNIQUE_PTR_TRIVIAL_ABI)
0132 #  define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI __attribute__((__trivial_abi__))
0133 #else
0134 #  define _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI
0135 #endif
0136 
0137 template <class _Tp, class _Dp = default_delete<_Tp> >
0138 class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr {
0139 public:
0140   typedef _Tp element_type;
0141   typedef _Dp deleter_type;
0142   typedef _LIBCPP_NODEBUG typename __pointer<_Tp, deleter_type>::type pointer;
0143 
0144   static_assert(!is_rvalue_reference<deleter_type>::value, "the specified deleter type cannot be an rvalue reference");
0145 
0146   // A unique_ptr contains the following members which may be trivially relocatable:
0147   // - pointer : this may be trivially relocatable, so it's checked
0148   // - deleter_type: this may be trivially relocatable, so it's checked
0149   //
0150   // This unique_ptr implementation only contains a pointer to the unique object and a deleter, so there are no
0151   // references to itself. This means that the entire structure is trivially relocatable if its members are.
0152   using __trivially_relocatable = __conditional_t<
0153       __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<deleter_type>::value,
0154       unique_ptr,
0155       void>;
0156 
0157 private:
0158   __compressed_pair<pointer, deleter_type> __ptr_;
0159 
0160   typedef _LIBCPP_NODEBUG __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
0161 
0162   template <bool _Dummy>
0163   using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
0164 
0165   template <bool _Dummy>
0166   using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
0167 
0168   template <bool _Dummy>
0169   using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
0170 
0171   template <bool _Dummy, class _Deleter = typename __dependent_type< __type_identity<deleter_type>, _Dummy>::type>
0172   using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
0173       __enable_if_t<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>;
0174 
0175   template <class _ArgType>
0176   using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t<is_constructible<deleter_type, _ArgType>::value>;
0177 
0178   template <class _UPtr, class _Up>
0179   using _EnableIfMoveConvertible _LIBCPP_NODEBUG =
0180       __enable_if_t< is_convertible<typename _UPtr::pointer, pointer>::value && !is_array<_Up>::value >;
0181 
0182   template <class _UDel>
0183   using _EnableIfDeleterConvertible _LIBCPP_NODEBUG =
0184       __enable_if_t< (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
0185                      (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) >;
0186 
0187   template <class _UDel>
0188   using _EnableIfDeleterAssignable = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >;
0189 
0190 public:
0191   template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
0192   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
0193 
0194   template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
0195   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
0196       : __ptr_(__value_init_tag(), __value_init_tag()) {}
0197 
0198   template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
0199   _LIBCPP_HIDE_FROM_ABI
0200   _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {}
0201 
0202   template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
0203   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
0204       : __ptr_(__p, __d) {}
0205 
0206   template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
0207   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
0208       : __ptr_(__p, std::move(__d)) {
0209     static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
0210   }
0211 
0212   template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > >
0213   _LIBCPP_HIDE_FROM_ABI unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
0214 
0215   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT
0216       : __ptr_(__u.release(), std::forward<deleter_type>(__u.get_deleter())) {}
0217 
0218   template <class _Up,
0219             class _Ep,
0220             class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
0221             class = _EnableIfDeleterConvertible<_Ep> >
0222   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
0223       : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {}
0224 
0225 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
0226   template <class _Up,
0227             __enable_if_t<is_convertible<_Up*, _Tp*>::value && is_same<_Dp, default_delete<_Tp> >::value, int> = 0>
0228   _LIBCPP_HIDE_FROM_ABI unique_ptr(auto_ptr<_Up>&& __p) _NOEXCEPT : __ptr_(__p.release(), __value_init_tag()) {}
0229 #endif
0230 
0231   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
0232     reset(__u.release());
0233     __ptr_.second() = std::forward<deleter_type>(__u.get_deleter());
0234     return *this;
0235   }
0236 
0237   template <class _Up,
0238             class _Ep,
0239             class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
0240             class = _EnableIfDeleterAssignable<_Ep> >
0241   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
0242     reset(__u.release());
0243     __ptr_.second() = std::forward<_Ep>(__u.get_deleter());
0244     return *this;
0245   }
0246 
0247 #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
0248   template <class _Up,
0249             __enable_if_t<is_convertible<_Up*, _Tp*>::value && is_same<_Dp, default_delete<_Tp> >::value, int> = 0>
0250   _LIBCPP_HIDE_FROM_ABI unique_ptr& operator=(auto_ptr<_Up> __p) {
0251     reset(__p.release());
0252     return *this;
0253   }
0254 #endif
0255 
0256 #ifdef _LIBCPP_CXX03_LANG
0257   unique_ptr(unique_ptr const&)            = delete;
0258   unique_ptr& operator=(unique_ptr const&) = delete;
0259 #endif
0260 
0261   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
0262 
0263   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
0264     reset();
0265     return *this;
0266   }
0267 
0268   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator*() const
0269       _NOEXCEPT_(__is_noexcept_deref_or_void<pointer>::value) {
0270     return *__ptr_.first();
0271   }
0272   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer operator->() const _NOEXCEPT { return __ptr_.first(); }
0273   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); }
0274   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); }
0275   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT {
0276     return __ptr_.second();
0277   }
0278   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT {
0279     return __ptr_.first() != nullptr;
0280   }
0281 
0282   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT {
0283     pointer __t    = __ptr_.first();
0284     __ptr_.first() = pointer();
0285     return __t;
0286   }
0287 
0288   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(pointer __p = pointer()) _NOEXCEPT {
0289     pointer __tmp  = __ptr_.first();
0290     __ptr_.first() = __p;
0291     if (__tmp)
0292       __ptr_.second()(__tmp);
0293   }
0294 
0295   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); }
0296 };
0297 
0298 template <class _Tp, class _Dp>
0299 class _LIBCPP_UNIQUE_PTR_TRIVIAL_ABI _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
0300 public:
0301   typedef _Tp element_type;
0302   typedef _Dp deleter_type;
0303   typedef typename __pointer<_Tp, deleter_type>::type pointer;
0304 
0305   // A unique_ptr contains the following members which may be trivially relocatable:
0306   // - pointer : this may be trivially relocatable, so it's checked
0307   // - deleter_type: this may be trivially relocatable, so it's checked
0308   //
0309   // This unique_ptr implementation only contains a pointer to the unique object and a deleter, so there are no
0310   // references to itself. This means that the entire structure is trivially relocatable if its members are.
0311   using __trivially_relocatable = __conditional_t<
0312       __libcpp_is_trivially_relocatable<pointer>::value && __libcpp_is_trivially_relocatable<deleter_type>::value,
0313       unique_ptr,
0314       void>;
0315 
0316 private:
0317   __compressed_pair<pointer, deleter_type> __ptr_;
0318 
0319   template <class _From>
0320   struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
0321 
0322   template <class _FromElem>
0323   struct _CheckArrayPointerConversion<_FromElem*>
0324       : integral_constant<bool,
0325                           is_same<_FromElem*, pointer>::value ||
0326                               (is_same<pointer, element_type*>::value &&
0327                                is_convertible<_FromElem (*)[], element_type (*)[]>::value) > {};
0328 
0329   typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
0330 
0331   template <bool _Dummy>
0332   using _LValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
0333 
0334   template <bool _Dummy>
0335   using _GoodRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
0336 
0337   template <bool _Dummy>
0338   using _BadRValRefType _LIBCPP_NODEBUG = typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
0339 
0340   template <bool _Dummy, class _Deleter = typename __dependent_type< __type_identity<deleter_type>, _Dummy>::type>
0341   using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG =
0342       __enable_if_t<is_default_constructible<_Deleter>::value && !is_pointer<_Deleter>::value>;
0343 
0344   template <class _ArgType>
0345   using _EnableIfDeleterConstructible _LIBCPP_NODEBUG = __enable_if_t<is_constructible<deleter_type, _ArgType>::value>;
0346 
0347   template <class _Pp>
0348   using _EnableIfPointerConvertible _LIBCPP_NODEBUG = __enable_if_t< _CheckArrayPointerConversion<_Pp>::value >;
0349 
0350   template <class _UPtr, class _Up, class _ElemT = typename _UPtr::element_type>
0351   using _EnableIfMoveConvertible _LIBCPP_NODEBUG =
0352       __enable_if_t< is_array<_Up>::value && is_same<pointer, element_type*>::value &&
0353                      is_same<typename _UPtr::pointer, _ElemT*>::value &&
0354                      is_convertible<_ElemT (*)[], element_type (*)[]>::value >;
0355 
0356   template <class _UDel>
0357   using _EnableIfDeleterConvertible _LIBCPP_NODEBUG =
0358       __enable_if_t< (is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
0359                      (!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value) >;
0360 
0361   template <class _UDel>
0362   using _EnableIfDeleterAssignable _LIBCPP_NODEBUG = __enable_if_t< is_assignable<_Dp&, _UDel&&>::value >;
0363 
0364 public:
0365   template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
0366   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(__value_init_tag(), __value_init_tag()) {}
0367 
0368   template <bool _Dummy = true, class = _EnableIfDeleterDefaultConstructible<_Dummy> >
0369   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
0370       : __ptr_(__value_init_tag(), __value_init_tag()) {}
0371 
0372   template <class _Pp,
0373             bool _Dummy = true,
0374             class       = _EnableIfDeleterDefaultConstructible<_Dummy>,
0375             class       = _EnableIfPointerConvertible<_Pp> >
0376   _LIBCPP_HIDE_FROM_ABI
0377   _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit unique_ptr(_Pp __p) _NOEXCEPT : __ptr_(__p, __value_init_tag()) {}
0378 
0379   template <class _Pp,
0380             bool _Dummy = true,
0381             class       = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
0382             class       = _EnableIfPointerConvertible<_Pp> >
0383   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT
0384       : __ptr_(__p, __d) {}
0385 
0386   template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
0387   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT
0388       : __ptr_(nullptr, __d) {}
0389 
0390   template <class _Pp,
0391             bool _Dummy = true,
0392             class       = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
0393             class       = _EnableIfPointerConvertible<_Pp> >
0394   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
0395       : __ptr_(__p, std::move(__d)) {
0396     static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
0397   }
0398 
0399   template <bool _Dummy = true, class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
0400   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
0401       : __ptr_(nullptr, std::move(__d)) {
0402     static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
0403   }
0404 
0405   template <class _Pp,
0406             bool _Dummy = true,
0407             class       = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
0408             class       = _EnableIfPointerConvertible<_Pp> >
0409   _LIBCPP_HIDE_FROM_ABI unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
0410 
0411   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr&& __u) _NOEXCEPT
0412       : __ptr_(__u.release(), std::forward<deleter_type>(__u.get_deleter())) {}
0413 
0414   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
0415     reset(__u.release());
0416     __ptr_.second() = std::forward<deleter_type>(__u.get_deleter());
0417     return *this;
0418   }
0419 
0420   template <class _Up,
0421             class _Ep,
0422             class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
0423             class = _EnableIfDeleterConvertible<_Ep> >
0424   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
0425       : __ptr_(__u.release(), std::forward<_Ep>(__u.get_deleter())) {}
0426 
0427   template <class _Up,
0428             class _Ep,
0429             class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
0430             class = _EnableIfDeleterAssignable<_Ep> >
0431   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
0432     reset(__u.release());
0433     __ptr_.second() = std::forward<_Ep>(__u.get_deleter());
0434     return *this;
0435   }
0436 
0437 #ifdef _LIBCPP_CXX03_LANG
0438   unique_ptr(unique_ptr const&)            = delete;
0439   unique_ptr& operator=(unique_ptr const&) = delete;
0440 #endif
0441 
0442 public:
0443   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(); }
0444 
0445   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 unique_ptr& operator=(nullptr_t) _NOEXCEPT {
0446     reset();
0447     return *this;
0448   }
0449 
0450   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 __add_lvalue_reference_t<_Tp> operator[](size_t __i) const {
0451     return __ptr_.first()[__i];
0452   }
0453   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer get() const _NOEXCEPT { return __ptr_.first(); }
0454 
0455   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 deleter_type& get_deleter() _NOEXCEPT { return __ptr_.second(); }
0456 
0457   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 const deleter_type& get_deleter() const _NOEXCEPT {
0458     return __ptr_.second();
0459   }
0460   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 explicit operator bool() const _NOEXCEPT {
0461     return __ptr_.first() != nullptr;
0462   }
0463 
0464   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 pointer release() _NOEXCEPT {
0465     pointer __t    = __ptr_.first();
0466     __ptr_.first() = pointer();
0467     return __t;
0468   }
0469 
0470   template <class _Pp, __enable_if_t<_CheckArrayPointerConversion<_Pp>::value, int> = 0>
0471   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(_Pp __p) _NOEXCEPT {
0472     pointer __tmp  = __ptr_.first();
0473     __ptr_.first() = __p;
0474     if (__tmp)
0475       __ptr_.second()(__tmp);
0476   }
0477 
0478   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void reset(nullptr_t = nullptr) _NOEXCEPT {
0479     pointer __tmp  = __ptr_.first();
0480     __ptr_.first() = nullptr;
0481     if (__tmp)
0482       __ptr_.second()(__tmp);
0483   }
0484 
0485   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void swap(unique_ptr& __u) _NOEXCEPT { __ptr_.swap(__u.__ptr_); }
0486 };
0487 
0488 template <class _Tp, class _Dp, __enable_if_t<__is_swappable_v<_Dp>, int> = 0>
0489 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 void
0490 swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {
0491   __x.swap(__y);
0492 }
0493 
0494 template <class _T1, class _D1, class _T2, class _D2>
0495 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
0496 operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
0497   return __x.get() == __y.get();
0498 }
0499 
0500 #if _LIBCPP_STD_VER <= 17
0501 template <class _T1, class _D1, class _T2, class _D2>
0502 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
0503   return !(__x == __y);
0504 }
0505 #endif
0506 
0507 template <class _T1, class _D1, class _T2, class _D2>
0508 inline _LIBCPP_HIDE_FROM_ABI bool operator<(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
0509   typedef typename unique_ptr<_T1, _D1>::pointer _P1;
0510   typedef typename unique_ptr<_T2, _D2>::pointer _P2;
0511   typedef typename common_type<_P1, _P2>::type _Vp;
0512   return less<_Vp>()(__x.get(), __y.get());
0513 }
0514 
0515 template <class _T1, class _D1, class _T2, class _D2>
0516 inline _LIBCPP_HIDE_FROM_ABI bool operator>(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
0517   return __y < __x;
0518 }
0519 
0520 template <class _T1, class _D1, class _T2, class _D2>
0521 inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
0522   return !(__y < __x);
0523 }
0524 
0525 template <class _T1, class _D1, class _T2, class _D2>
0526 inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
0527   return !(__x < __y);
0528 }
0529 
0530 #if _LIBCPP_STD_VER >= 20
0531 template <class _T1, class _D1, class _T2, class _D2>
0532   requires three_way_comparable_with<typename unique_ptr<_T1, _D1>::pointer, typename unique_ptr<_T2, _D2>::pointer>
0533 _LIBCPP_HIDE_FROM_ABI
0534 compare_three_way_result_t<typename unique_ptr<_T1, _D1>::pointer, typename unique_ptr<_T2, _D2>::pointer>
0535 operator<=>(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {
0536   return compare_three_way()(__x.get(), __y.get());
0537 }
0538 #endif
0539 
0540 template <class _T1, class _D1>
0541 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool
0542 operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT {
0543   return !__x;
0544 }
0545 
0546 #if _LIBCPP_STD_VER <= 17
0547 template <class _T1, class _D1>
0548 inline _LIBCPP_HIDE_FROM_ABI bool operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT {
0549   return !__x;
0550 }
0551 
0552 template <class _T1, class _D1>
0553 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT {
0554   return static_cast<bool>(__x);
0555 }
0556 
0557 template <class _T1, class _D1>
0558 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT {
0559   return static_cast<bool>(__x);
0560 }
0561 #endif // _LIBCPP_STD_VER <= 17
0562 
0563 template <class _T1, class _D1>
0564 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
0565   typedef typename unique_ptr<_T1, _D1>::pointer _P1;
0566   return less<_P1>()(__x.get(), nullptr);
0567 }
0568 
0569 template <class _T1, class _D1>
0570 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x) {
0571   typedef typename unique_ptr<_T1, _D1>::pointer _P1;
0572   return less<_P1>()(nullptr, __x.get());
0573 }
0574 
0575 template <class _T1, class _D1>
0576 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
0577   return nullptr < __x;
0578 }
0579 
0580 template <class _T1, class _D1>
0581 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x) {
0582   return __x < nullptr;
0583 }
0584 
0585 template <class _T1, class _D1>
0586 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
0587   return !(nullptr < __x);
0588 }
0589 
0590 template <class _T1, class _D1>
0591 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x) {
0592   return !(__x < nullptr);
0593 }
0594 
0595 template <class _T1, class _D1>
0596 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
0597   return !(__x < nullptr);
0598 }
0599 
0600 template <class _T1, class _D1>
0601 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 bool operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x) {
0602   return !(nullptr < __x);
0603 }
0604 
0605 #if _LIBCPP_STD_VER >= 20
0606 template <class _T1, class _D1>
0607   requires three_way_comparable< typename unique_ptr<_T1, _D1>::pointer>
0608 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 compare_three_way_result_t<typename unique_ptr<_T1, _D1>::pointer>
0609 operator<=>(const unique_ptr<_T1, _D1>& __x, nullptr_t) {
0610   return compare_three_way()(__x.get(), static_cast<typename unique_ptr<_T1, _D1>::pointer>(nullptr));
0611 }
0612 #endif
0613 
0614 #if _LIBCPP_STD_VER >= 14
0615 
0616 template <class _Tp>
0617 struct __unique_if {
0618   typedef unique_ptr<_Tp> __unique_single;
0619 };
0620 
0621 template <class _Tp>
0622 struct __unique_if<_Tp[]> {
0623   typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
0624 };
0625 
0626 template <class _Tp, size_t _Np>
0627 struct __unique_if<_Tp[_Np]> {
0628   typedef void __unique_array_known_bound;
0629 };
0630 
0631 template <class _Tp, class... _Args>
0632 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single
0633 make_unique(_Args&&... __args) {
0634   return unique_ptr<_Tp>(new _Tp(std::forward<_Args>(__args)...));
0635 }
0636 
0637 template <class _Tp>
0638 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
0639 make_unique(size_t __n) {
0640   typedef __remove_extent_t<_Tp> _Up;
0641   return unique_ptr<_Tp>(new _Up[__n]());
0642 }
0643 
0644 template <class _Tp, class... _Args>
0645 typename __unique_if<_Tp>::__unique_array_known_bound make_unique(_Args&&...) = delete;
0646 
0647 #endif // _LIBCPP_STD_VER >= 14
0648 
0649 #if _LIBCPP_STD_VER >= 20
0650 
0651 template <class _Tp>
0652 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_single
0653 make_unique_for_overwrite() {
0654   return unique_ptr<_Tp>(new _Tp);
0655 }
0656 
0657 template <class _Tp>
0658 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX23 typename __unique_if<_Tp>::__unique_array_unknown_bound
0659 make_unique_for_overwrite(size_t __n) {
0660   return unique_ptr<_Tp>(new __remove_extent_t<_Tp>[__n]);
0661 }
0662 
0663 template <class _Tp, class... _Args>
0664 typename __unique_if<_Tp>::__unique_array_known_bound make_unique_for_overwrite(_Args&&...) = delete;
0665 
0666 #endif // _LIBCPP_STD_VER >= 20
0667 
0668 template <class _Tp>
0669 struct _LIBCPP_TEMPLATE_VIS hash;
0670 
0671 template <class _Tp, class _Dp>
0672 #ifdef _LIBCPP_CXX03_LANG
0673 struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
0674 #else
0675 struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper< unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
0676 #endif
0677 {
0678 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
0679   _LIBCPP_DEPRECATED_IN_CXX17 typedef unique_ptr<_Tp, _Dp> argument_type;
0680   _LIBCPP_DEPRECATED_IN_CXX17 typedef size_t result_type;
0681 #endif
0682 
0683   _LIBCPP_HIDE_FROM_ABI size_t operator()(const unique_ptr<_Tp, _Dp>& __ptr) const {
0684     typedef typename unique_ptr<_Tp, _Dp>::pointer pointer;
0685     return hash<pointer>()(__ptr.get());
0686   }
0687 };
0688 
0689 _LIBCPP_END_NAMESPACE_STD
0690 
0691 _LIBCPP_POP_MACROS
0692 
0693 #endif // _LIBCPP___CXX03___MEMORY_UNIQUE_PTR_H