Warning, /include/c++/v1/memory 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_MEMORY
0011 #define _LIBCPP_MEMORY
0012
0013 // clang-format off
0014
0015 /*
0016 memory synopsis
0017
0018 namespace std
0019 {
0020
0021 struct allocator_arg_t { };
0022 inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
0023
0024 template <class T, class Alloc> struct uses_allocator;
0025
0026 template <class Ptr>
0027 struct pointer_traits
0028 {
0029 typedef Ptr pointer;
0030 typedef <details> element_type;
0031 typedef <details> difference_type;
0032
0033 template <class U> using rebind = <details>;
0034
0035 static pointer pointer_to(<details>);
0036 };
0037
0038 template <class T>
0039 struct pointer_traits<T*>
0040 {
0041 typedef T* pointer;
0042 typedef T element_type;
0043 typedef ptrdiff_t difference_type;
0044
0045 template <class U> using rebind = U*;
0046
0047 static pointer pointer_to(<details>) noexcept; // constexpr in C++20
0048 };
0049
0050 template <class T> constexpr T* to_address(T* p) noexcept; // C++20
0051 template <class Ptr> constexpr auto to_address(const Ptr& p) noexcept; // C++20
0052
0053 template <class Alloc>
0054 struct allocator_traits
0055 {
0056 typedef Alloc allocator_type;
0057 typedef typename allocator_type::value_type
0058 value_type;
0059
0060 typedef Alloc::pointer | value_type* pointer;
0061 typedef Alloc::const_pointer
0062 | pointer_traits<pointer>::rebind<const value_type>
0063 const_pointer;
0064 typedef Alloc::void_pointer
0065 | pointer_traits<pointer>::rebind<void>
0066 void_pointer;
0067 typedef Alloc::const_void_pointer
0068 | pointer_traits<pointer>::rebind<const void>
0069 const_void_pointer;
0070 typedef Alloc::difference_type
0071 | pointer_traits<pointer>::difference_type
0072 difference_type;
0073 typedef Alloc::size_type
0074 | make_unsigned<difference_type>::type
0075 size_type;
0076 typedef Alloc::propagate_on_container_copy_assignment
0077 | false_type propagate_on_container_copy_assignment;
0078 typedef Alloc::propagate_on_container_move_assignment
0079 | false_type propagate_on_container_move_assignment;
0080 typedef Alloc::propagate_on_container_swap
0081 | false_type propagate_on_container_swap;
0082 typedef Alloc::is_always_equal
0083 | is_empty is_always_equal;
0084
0085 template <class T> using rebind_alloc = Alloc::rebind<T>::other | Alloc<T, Args...>;
0086 template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
0087
0088 static pointer allocate(allocator_type& a, size_type n); // constexpr and [[nodiscard]] in C++20
0089 static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // constexpr and [[nodiscard]] in C++20
0090
0091 [[nodiscard]] static constexpr allocation_result<pointer, size_type>
0092 allocate_at_least(Alloc& a, size_type n); // Since C++23
0093
0094 static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; // constexpr in C++20
0095
0096 template <class T, class... Args>
0097 static void construct(allocator_type& a, T* p, Args&&... args); // constexpr in C++20
0098
0099 template <class T>
0100 static void destroy(allocator_type& a, T* p); // constexpr in C++20
0101
0102 static size_type max_size(const allocator_type& a); // noexcept in C++14, constexpr in C++20
0103 static allocator_type select_on_container_copy_construction(const allocator_type& a); // constexpr in C++20
0104 };
0105
0106 template<class Pointer, class SizeType = size_t>
0107 struct allocation_result {
0108 Pointer ptr;
0109 SizeType count;
0110 }; // Since C++23
0111
0112 template <>
0113 class allocator<void> // removed in C++20
0114 {
0115 public:
0116 typedef void* pointer;
0117 typedef const void* const_pointer;
0118 typedef void value_type;
0119
0120 template <class _Up> struct rebind {typedef allocator<_Up> other;};
0121 };
0122
0123 template <class T>
0124 class allocator
0125 {
0126 public:
0127 typedef size_t size_type;
0128 typedef ptrdiff_t difference_type;
0129 typedef T* pointer; // deprecated in C++17, removed in C++20
0130 typedef const T* const_pointer; // deprecated in C++17, removed in C++20
0131 typedef typename add_lvalue_reference<T>::type
0132 reference; // deprecated in C++17, removed in C++20
0133 typedef typename add_lvalue_reference<const T>::type
0134 const_reference; // deprecated in C++17, removed in C++20
0135
0136 typedef T value_type;
0137
0138 template <class U> struct rebind {typedef allocator<U> other;}; // deprecated in C++17, removed in C++20
0139
0140 typedef true_type propagate_on_container_move_assignment;
0141 typedef true_type is_always_equal; // Deprecated in C++23, removed in C++26
0142
0143 constexpr allocator() noexcept; // constexpr in C++20
0144 constexpr allocator(const allocator&) noexcept; // constexpr in C++20
0145 template <class U>
0146 constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
0147 ~allocator(); // constexpr in C++20
0148 pointer address(reference x) const noexcept; // deprecated in C++17, removed in C++20
0149 const_pointer address(const_reference x) const noexcept; // deprecated in C++17, removed in C++20
0150 T* allocate(size_t n, const void* hint); // deprecated in C++17, removed in C++20
0151 T* allocate(size_t n); // constexpr in C++20
0152 void deallocate(T* p, size_t n) noexcept; // constexpr in C++20
0153 size_type max_size() const noexcept; // deprecated in C++17, removed in C++20
0154 template<class U, class... Args>
0155 void construct(U* p, Args&&... args); // deprecated in C++17, removed in C++20
0156 template <class U>
0157 void destroy(U* p); // deprecated in C++17, removed in C++20
0158 };
0159
0160 template <class T, class U>
0161 bool operator==(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20
0162
0163 template <class T, class U>
0164 bool operator!=(const allocator<T>&, const allocator<U>&) noexcept; // removed in C++20
0165
0166 template <class OutputIterator, class T>
0167 class raw_storage_iterator // deprecated in C++17, removed in C++20
0168 : public iterator<output_iterator_tag, void, void, void, void> // until C++17
0169 {
0170 public:
0171 typedef output_iterator_tag iterator_category;
0172 typedef void value_type;
0173 typedef void difference_type; // until C++20
0174 typedef ptrdiff_t difference_type; // since C++20
0175 typedef void pointer;
0176 typedef void reference;
0177
0178 explicit raw_storage_iterator(OutputIterator x);
0179 raw_storage_iterator& operator*();
0180 raw_storage_iterator& operator=(const T& element);
0181 raw_storage_iterator& operator++();
0182 raw_storage_iterator operator++(int);
0183 };
0184
0185 template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; // deprecated in C++17, removed in C++20
0186 template <class T> void return_temporary_buffer(T* p) noexcept; // deprecated in C++17, removed in C++20
0187
0188 template <class T> T* addressof(T& r) noexcept;
0189 template <class T> T* addressof(const T&& r) noexcept = delete;
0190
0191 template <class InputIterator, class ForwardIterator>
0192 ForwardIterator
0193 uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
0194
0195 namespace ranges {
0196
0197 template<class InputIterator, class OutputIterator>
0198 using uninitialized_copy_result = in_out_result<InputIterator, OutputIterator>; // since C++20
0199
0200 template<input_iterator InputIterator, sentinel-for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel2>
0201 requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>>
0202 uninitialized_copy_result<InputIterator, OutputIterator>
0203 uninitialized_copy(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20
0204
0205 template<input_range InputRange, nothrow-forward-range OutputRange>
0206 requires constructible_from<range_value_t<OutputRange>, range_reference_t<InputRange>>
0207 uninitialized_copy_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>>
0208 uninitialized_copy(InputRange&& in_range, OutputRange&& out_range); // since C++20
0209
0210 }
0211
0212 template <class InputIterator, class Size, class ForwardIterator>
0213 ForwardIterator
0214 uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
0215
0216 namespace ranges {
0217
0218 template<class InputIterator, class OutputIterator>
0219 using uninitialized_copy_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20
0220
0221 template<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel>
0222 requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>>
0223 uninitialized_copy_n_result<InputIterator, OutputIterator>
0224 uninitialized_copy_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20
0225
0226 }
0227
0228 template <class ForwardIterator, class T>
0229 void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
0230
0231 namespace ranges {
0232
0233 template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel, class T>
0234 requires constructible_from<iter_value_t<ForwardIterator>, const T&>
0235 ForwardIterator uninitialized_fill(ForwardIterator first, Sentinel last, const T& x); // since C++20
0236
0237 template <nothrow-forward-range ForwardRange, class T>
0238 requires constructible_from<range_value_t<ForwardRange>, const T&>
0239 borrowed_iterator_t<ForwardRange> uninitialized_fill(ForwardRange&& range, const T& x); // since C++20
0240
0241 }
0242
0243 template <class ForwardIterator, class Size, class T>
0244 ForwardIterator
0245 uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
0246
0247 namespace ranges {
0248
0249 template <nothrow-forward-iterator ForwardIterator, class T>
0250 requires constructible_from<iter_value_t<ForwardIterator>, const T&>
0251 ForwardIterator uninitialized_fill_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
0252
0253 }
0254
0255 template <class T, class ...Args>
0256 constexpr T* construct_at(T* location, Args&& ...args); // since C++20
0257
0258 namespace ranges {
0259 template<class T, class... Args>
0260 constexpr T* construct_at(T* location, Args&&... args); // since C++20
0261 }
0262
0263 template <class T>
0264 void destroy_at(T* location); // constexpr in C++20
0265
0266 namespace ranges {
0267 template<destructible T>
0268 constexpr void destroy_at(T* location) noexcept; // since C++20
0269 }
0270
0271 template <class ForwardIterator>
0272 void destroy(ForwardIterator first, ForwardIterator last); // constexpr in C++20
0273
0274 namespace ranges {
0275 template<nothrow-input-iterator InputIterator, nothrow-sentinel-for<InputIterator> Sentinel>
0276 requires destructible<iter_value_t<InputIterator>>
0277 constexpr InputIterator destroy(InputIterator first, Sentinel last) noexcept; // since C++20
0278 template<nothrow-input-range InputRange>
0279 requires destructible<range_value_t<InputRange>>
0280 constexpr borrowed_iterator_t<InputRange> destroy(InputRange&& range) noexcept; // since C++20
0281 }
0282
0283 template <class ForwardIterator, class Size>
0284 ForwardIterator destroy_n(ForwardIterator first, Size n); // constexpr in C++20
0285
0286 namespace ranges {
0287 template<nothrow-input-iterator InputIterator>
0288 requires destructible<iter_value_t<InputIterator>>
0289 constexpr InputIterator destroy_n(InputIterator first, iter_difference_t<InputIterator> n) noexcept; // since C++20
0290 }
0291
0292 template <class InputIterator, class ForwardIterator>
0293 ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
0294
0295 namespace ranges {
0296
0297 template<class InputIterator, class OutputIterator>
0298 using uninitialized_move_result = in_out_result<InputIterator, OutputIterator>; // since C++20
0299
0300 template <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<O> Sentinel2>
0301 requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>>
0302 uninitialized_move_result<InputIterator, OutputIterator>
0303 uninitialized_move(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20
0304
0305 template<input_range InputRange, nothrow-forward-range OutputRange>
0306 requires constructible_from<range_value_t<OutputRange>, range_rvalue_reference_t<InputRange>>
0307 uninitialized_move_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>>
0308 uninitialized_move(InputRange&& in_range, OutputRange&& out_range); // since C++20
0309
0310 }
0311
0312 template <class InputIterator, class Size, class ForwardIterator>
0313 pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
0314
0315 namespace ranges {
0316
0317 template<class InputIterator, class OutputIterator>
0318 using uninitialized_move_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20
0319
0320 template<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel>
0321 requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>>
0322 uninitialized_move_n_result<InputIterator, OutputIterator>
0323 uninitialized_move_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20
0324
0325 }
0326
0327 template <class ForwardIterator>
0328 void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
0329
0330 namespace ranges {
0331
0332 template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel>
0333 requires default_initializable<iter_value_t<ForwardIterator>>
0334 ForwardIterator uninitialized_value_construct(ForwardIterator first, Sentinel last); // since C++20
0335
0336 template <nothrow-forward-range ForwardRange>
0337 requires default_initializable<range_value_t<ForwardRange>>
0338 borrowed_iterator_t<ForwardRange> uninitialized_value_construct(ForwardRange&& r); // since C++20
0339
0340 }
0341
0342 template <class ForwardIterator, class Size>
0343 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
0344
0345 namespace ranges {
0346
0347 template <nothrow-forward-iterator ForwardIterator>
0348 requires default_initializable<iter_value_t<ForwardIterator>>
0349 ForwardIterator uninitialized_value_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
0350
0351 }
0352
0353 template <class ForwardIterator>
0354 void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
0355
0356 namespace ranges {
0357
0358 template <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel>
0359 requires default_initializable<iter_value_t<ForwardIterator>>
0360 ForwardIterator uninitialized_default_construct(ForwardIterator first, Sentinel last); // since C++20
0361
0362 template <nothrow-forward-range ForwardRange>
0363 requires default_initializable<range_value_t<ForwardRange>>
0364 borrowed_iterator_t<ForwardRange> uninitialized_default_construct(ForwardRange&& r); // since C++20
0365
0366 }
0367
0368 template <class ForwardIterator, class Size>
0369 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
0370
0371 namespace ranges {
0372
0373 template <nothrow-forward-iterator ForwardIterator>
0374 requires default_initializable<iter_value_t<ForwardIterator>>
0375 ForwardIterator uninitialized_default_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20
0376
0377 }
0378
0379 template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17
0380
0381 template<class X>
0382 class auto_ptr // deprecated in C++11, removed in C++17
0383 {
0384 public:
0385 typedef X element_type;
0386
0387 explicit auto_ptr(X* p =0) throw();
0388 auto_ptr(auto_ptr&) throw();
0389 template<class Y> auto_ptr(auto_ptr<Y>&) throw();
0390 auto_ptr& operator=(auto_ptr&) throw();
0391 template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
0392 auto_ptr& operator=(auto_ptr_ref<X> r) throw();
0393 ~auto_ptr() throw();
0394
0395 typename add_lvalue_reference<X>::type operator*() const throw();
0396 X* operator->() const throw();
0397 X* get() const throw();
0398 X* release() throw();
0399 void reset(X* p =0) throw();
0400
0401 auto_ptr(auto_ptr_ref<X>) throw();
0402 template<class Y> operator auto_ptr_ref<Y>() throw();
0403 template<class Y> operator auto_ptr<Y>() throw();
0404 };
0405
0406 template <class T>
0407 struct default_delete
0408 {
0409 constexpr default_delete() noexcept = default;
0410 template <class U> constexpr default_delete(const default_delete<U>&) noexcept; // constexpr since C++23
0411
0412 constexpr void operator()(T*) const noexcept; // constexpr since C++23
0413 };
0414
0415 template <class T>
0416 struct default_delete<T[]>
0417 {
0418 constexpr default_delete() noexcept = default;
0419 template <class U> constexpr default_delete(const default_delete <U[]>&) noexcept; // constexpr since C++23
0420 constexpr void operator()(T*) const noexcept; // constexpr since C++23
0421 template <class U> void operator()(U*) const = delete;
0422 };
0423
0424 template <class T, class D = default_delete<T>>
0425 class unique_ptr
0426 {
0427 public:
0428 typedef see below pointer;
0429 typedef T element_type;
0430 typedef D deleter_type;
0431
0432 // constructors
0433 constexpr unique_ptr() noexcept;
0434 constexpr explicit unique_ptr(pointer p) noexcept; // constexpr since C++23
0435 constexpr unique_ptr(pointer p, see below d1) noexcept; // constexpr since C++23
0436 constexpr unique_ptr(pointer p, see below d2) noexcept; // constexpr since C++23
0437 constexpr unique_ptr(unique_ptr&& u) noexcept; // constexpr since C++23
0438 constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { }
0439 template <class U, class E>
0440 constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept; // constexpr since C++23
0441 template <class U>
0442 unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
0443
0444 // destructor
0445 constexpr ~unique_ptr(); // constexpr since C++23
0446
0447 // assignment
0448 constexpr unique_ptr& operator=(unique_ptr&& u) noexcept; // constexpr since C++23
0449 template <class U, class E>
0450 constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; // constexpr since C++23
0451 constexpr unique_ptr& operator=(nullptr_t) noexcept; // constexpr since C++23
0452
0453 // observers
0454 constexpr
0455 add_lvalue_reference<T>::type operator*() const noexcept(see below); // constexpr since C++23
0456 constexpr pointer operator->() const noexcept; // constexpr since C++23
0457 constexpr pointer get() const noexcept; // constexpr since C++23
0458 constexpr deleter_type& get_deleter() noexcept; // constexpr since C++23
0459 constexpr const deleter_type& get_deleter() const noexcept; // constexpr since C++23
0460 constexpr explicit operator bool() const noexcept; // constexpr since C++23
0461
0462 // modifiers
0463 constexpr pointer release() noexcept; // constexpr since C++23
0464 constexpr void reset(pointer p = pointer()) noexcept; // constexpr since C++23
0465 constexpr void swap(unique_ptr& u) noexcept; // constexpr since C++23
0466 };
0467
0468 template <class T, class D>
0469 class unique_ptr<T[], D>
0470 {
0471 public:
0472 typedef implementation-defined pointer;
0473 typedef T element_type;
0474 typedef D deleter_type;
0475
0476 // constructors
0477 constexpr unique_ptr() noexcept;
0478 constexpr explicit unique_ptr(pointer p) noexcept; // constexpr since C++23
0479 constexpr unique_ptr(pointer p, see below d) noexcept; // constexpr since C++23
0480 constexpr unique_ptr(pointer p, see below d) noexcept; // constexpr since C++23
0481 constexpr unique_ptr(unique_ptr&& u) noexcept; // constexpr since C++23
0482 template <class U, class E>
0483 constexpr unique_ptr(unique_ptr <U, E>&& u) noexcept; // constexpr since C++23
0484 constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { }
0485
0486 // destructor
0487 constexpr ~unique_ptr(); // constexpr since C++23
0488
0489 // assignment
0490 constexpr unique_ptr& operator=(unique_ptr&& u) noexcept; // constexpr since C++23
0491 template <class U, class E>
0492 constexpr unique_ptr& operator=(unique_ptr <U, E>&& u) noexcept; // constexpr since C++23
0493 constexpr unique_ptr& operator=(nullptr_t) noexcept; // constexpr since C++23
0494
0495 // observers
0496 constexpr T& operator[](size_t i) const; // constexpr since C++23
0497 constexpr pointer get() const noexcept; // constexpr since C++23
0498 constexpr deleter_type& get_deleter() noexcept; // constexpr since C++23
0499 constexpr const deleter_type& get_deleter() const noexcept; // constexpr since C++23
0500 constexpr explicit operator bool() const noexcept; // constexpr since C++23
0501
0502 // modifiers
0503 constexpr pointer release() noexcept; // constexpr since C++23
0504 constexpr void reset(pointer p = pointer()) noexcept; // constexpr since C++23
0505 constexpr void reset(nullptr_t) noexcept; // constexpr since C++23
0506 template <class U> void reset(U) = delete;
0507 constexpr void swap(unique_ptr& u) noexcept; // constexpr since C++23
0508 };
0509
0510 template <class T, class D>
0511 constexpr void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; // constexpr since C++23
0512
0513 template <class T1, class D1, class T2, class D2>
0514 constexpr bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); // constexpr since C++23
0515 template <class T1, class D1, class T2, class D2>
0516 bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); // removed in C++20
0517 template <class T1, class D1, class T2, class D2>
0518 bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
0519 template <class T1, class D1, class T2, class D2>
0520 bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
0521 template <class T1, class D1, class T2, class D2>
0522 bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
0523 template <class T1, class D1, class T2, class D2>
0524 bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
0525 template<class T1, class D1, class T2, class D2>
0526 requires three_way_comparable_with<typename unique_ptr<T1, D1>::pointer,
0527 typename unique_ptr<T2, D2>::pointer>
0528 compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer,
0529 typename unique_ptr<T2, D2>::pointer>
0530 operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); // C++20
0531
0532 template <class T, class D>
0533 constexpr bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; // constexpr since C++23
0534 template <class T, class D>
0535 bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; // removed in C++20
0536 template <class T, class D>
0537 bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; // removed in C++20
0538 template <class T, class D>
0539 bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; // removed in C++20
0540
0541 template <class T, class D>
0542 constexpr bool operator<(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23
0543 template <class T, class D>
0544 constexpr bool operator<(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23
0545 template <class T, class D>
0546 constexpr bool operator<=(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23
0547 template <class T, class D>
0548 constexpr bool operator<=(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23
0549 template <class T, class D>
0550 constexpr bool operator>(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23
0551 template <class T, class D>
0552 constexpr bool operator>(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23
0553 template <class T, class D>
0554 constexpr bool operator>=(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23
0555 template <class T, class D>
0556 constexpr bool operator>=(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23
0557 template<class T, class D>
0558 requires three_way_comparable<typename unique_ptr<T, D>::pointer>
0559 compare_three_way_result_t<typename unique_ptr<T, D>::pointer>
0560 constexpr operator<=>(const unique_ptr<T, D>& x, nullptr_t); // C++20, constexpr since C++23
0561
0562 class bad_weak_ptr
0563 : public std::exception
0564 {
0565 bad_weak_ptr() noexcept;
0566 };
0567
0568 template<class T, class... Args>
0569 constexpr unique_ptr<T> make_unique(Args&&... args); // C++14, constexpr since C++23
0570 template<class T>
0571 constexpr unique_ptr<T> make_unique(size_t n); // C++14, constexpr since C++23
0572 template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
0573
0574 template<class T>
0575 constexpr unique_ptr<T> make_unique_for_overwrite(); // T is not array, C++20, constexpr since C++23
0576 template<class T>
0577 constexpr unique_ptr<T> make_unique_for_overwrite(size_t n); // T is U[], C++20, constexpr since C++23
0578 template<class T, class... Args>
0579 unspecified make_unique_for_overwrite(Args&&...) = delete; // T is U[N], C++20
0580
0581 template<class E, class T, class Y, class D>
0582 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
0583
0584 template<class T>
0585 class shared_ptr
0586 {
0587 public:
0588 typedef T element_type; // until C++17
0589 typedef remove_extent_t<T> element_type; // since C++17
0590 typedef weak_ptr<T> weak_type; // C++17
0591
0592 // constructors:
0593 constexpr shared_ptr() noexcept;
0594 template<class Y> explicit shared_ptr(Y* p);
0595 template<class Y, class D> shared_ptr(Y* p, D d);
0596 template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
0597 template <class D> shared_ptr(nullptr_t p, D d);
0598 template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
0599 template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
0600 shared_ptr(const shared_ptr& r) noexcept;
0601 template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
0602 shared_ptr(shared_ptr&& r) noexcept;
0603 template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
0604 template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
0605 template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
0606 template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
0607 shared_ptr(nullptr_t) : shared_ptr() { }
0608
0609 // destructor:
0610 ~shared_ptr();
0611
0612 // assignment:
0613 shared_ptr& operator=(const shared_ptr& r) noexcept;
0614 template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
0615 shared_ptr& operator=(shared_ptr&& r) noexcept;
0616 template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
0617 template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
0618 template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
0619
0620 // modifiers:
0621 void swap(shared_ptr& r) noexcept;
0622 void reset() noexcept;
0623 template<class Y> void reset(Y* p);
0624 template<class Y, class D> void reset(Y* p, D d);
0625 template<class Y, class D, class A> void reset(Y* p, D d, A a);
0626
0627 // observers:
0628 T* get() const noexcept;
0629 T& operator*() const noexcept;
0630 T* operator->() const noexcept;
0631 long use_count() const noexcept;
0632 bool unique() const noexcept; // deprected in C++17, removed in C++20
0633 explicit operator bool() const noexcept;
0634 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
0635 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
0636 };
0637
0638 template<class T>
0639 shared_ptr(weak_ptr<T>) -> shared_ptr<T>;
0640 template<class T, class D>
0641 shared_ptr(unique_ptr<T, D>) -> shared_ptr<T>;
0642
0643 // shared_ptr comparisons:
0644 template<class T, class U>
0645 bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
0646 template<class T, class U>
0647 bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20
0648 template<class T, class U>
0649 bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20
0650 template<class T, class U>
0651 bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20
0652 template<class T, class U>
0653 bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20
0654 template<class T, class U>
0655 bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20
0656 template<class T, class U>
0657 strong_ordering operator<=>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // C++20
0658
0659 template <class T>
0660 bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
0661 template <class T>
0662 bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20
0663 template <class T>
0664 bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20
0665 template <class T>
0666 bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20
0667 template <class T>
0668 bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20
0669 template <class T>
0670 bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20
0671 template <class T>
0672 bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20
0673 template <class T>
0674 bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20
0675 template <class T>
0676 bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20
0677 template <class T>
0678 bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20
0679 template <class T>
0680 bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20
0681 template <class T>
0682 bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20
0683 template<class T>
0684 strong_ordering operator<=>(shared_ptr<T> const& x, nullptr_t) noexcept; // C++20
0685
0686 // shared_ptr specialized algorithms:
0687 template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
0688
0689 // shared_ptr casts:
0690 template<class T, class U>
0691 shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
0692 template<class T, class U>
0693 shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
0694 template<class T, class U>
0695 shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
0696
0697 // shared_ptr I/O:
0698 template<class E, class T, class Y>
0699 basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
0700
0701 // shared_ptr get_deleter:
0702 template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
0703
0704 template<class T, class... Args>
0705 shared_ptr<T> make_shared(Args&&... args); // T is not an array
0706 template<class T, class A, class... Args>
0707 shared_ptr<T> allocate_shared(const A& a, Args&&... args); // T is not an array
0708
0709 template<class T>
0710 shared_ptr<T> make_shared(size_t N); // T is U[] (since C++20)
0711 template<class T, class A>
0712 shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[] (since C++20)
0713
0714 template<class T>
0715 shared_ptr<T> make_shared(); // T is U[N] (since C++20)
0716 template<class T, class A>
0717 shared_ptr<T> allocate_shared(const A& a); // T is U[N] (since C++20)
0718
0719 template<class T>
0720 shared_ptr<T> make_shared(size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)
0721 template<class T, class A>
0722 shared_ptr<T> allocate_shared(const A& a, size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20)
0723
0724 template<class T> shared_ptr<T>
0725 make_shared(const remove_extent_t<T>& u); // T is U[N] (since C++20)
0726 template<class T, class A>
0727 shared_ptr<T> allocate_shared(const A& a, const remove_extent_t<T>& u); // T is U[N] (since C++20)
0728
0729 template<class T>
0730 shared_ptr<T> make_shared_for_overwrite(); // T is not U[], C++20
0731 template<class T, class A>
0732 shared_ptr<T> allocate_shared_for_overwrite(const A& a); // T is not U[], C++20
0733
0734 template<class T>
0735 shared_ptr<T> make_shared_for_overwrite(size_t N); // T is U[], C++20
0736 template<class T, class A>
0737 shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); // T is U[], C++20
0738
0739 template<class T>
0740 class weak_ptr
0741 {
0742 public:
0743 typedef T element_type; // until C++17
0744 typedef remove_extent_t<T> element_type; // since C++17
0745
0746 // constructors
0747 constexpr weak_ptr() noexcept;
0748 template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
0749 weak_ptr(weak_ptr const& r) noexcept;
0750 template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
0751 weak_ptr(weak_ptr&& r) noexcept; // C++14
0752 template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
0753
0754 // destructor
0755 ~weak_ptr();
0756
0757 // assignment
0758 weak_ptr& operator=(weak_ptr const& r) noexcept;
0759 template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
0760 template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
0761 weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
0762 template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
0763
0764 // modifiers
0765 void swap(weak_ptr& r) noexcept;
0766 void reset() noexcept;
0767
0768 // observers
0769 long use_count() const noexcept;
0770 bool expired() const noexcept;
0771 shared_ptr<T> lock() const noexcept;
0772 template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
0773 template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
0774 };
0775
0776 template<class T>
0777 weak_ptr(shared_ptr<T>) -> weak_ptr<T>;
0778
0779 // weak_ptr specialized algorithms:
0780 template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
0781
0782 // class owner_less:
0783 template<class T> struct owner_less;
0784
0785 template<class T>
0786 struct owner_less<shared_ptr<T> >
0787 : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
0788 {
0789 typedef bool result_type;
0790 bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
0791 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
0792 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
0793 };
0794
0795 template<class T>
0796 struct owner_less<weak_ptr<T> >
0797 : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
0798 {
0799 typedef bool result_type;
0800 bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
0801 bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
0802 bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
0803 };
0804
0805 template <> // Added in C++14
0806 struct owner_less<void>
0807 {
0808 template <class _Tp, class _Up>
0809 bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
0810 template <class _Tp, class _Up>
0811 bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
0812 template <class _Tp, class _Up>
0813 bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
0814 template <class _Tp, class _Up>
0815 bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
0816
0817 typedef void is_transparent;
0818 };
0819
0820 template<class T>
0821 class enable_shared_from_this
0822 {
0823 protected:
0824 constexpr enable_shared_from_this() noexcept;
0825 enable_shared_from_this(enable_shared_from_this const&) noexcept;
0826 enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
0827 ~enable_shared_from_this();
0828 public:
0829 shared_ptr<T> shared_from_this();
0830 shared_ptr<T const> shared_from_this() const;
0831 };
0832
0833 template<class T>
0834 bool atomic_is_lock_free(const shared_ptr<T>* p);
0835 template<class T>
0836 shared_ptr<T> atomic_load(const shared_ptr<T>* p);
0837 template<class T>
0838 shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
0839 template<class T>
0840 void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
0841 template<class T>
0842 void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
0843 template<class T>
0844 shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
0845 template<class T>
0846 shared_ptr<T>
0847 atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
0848 template<class T>
0849 bool
0850 atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
0851 template<class T>
0852 bool
0853 atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
0854 template<class T>
0855 bool
0856 atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
0857 shared_ptr<T> w, memory_order success,
0858 memory_order failure);
0859 template<class T>
0860 bool
0861 atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
0862 shared_ptr<T> w, memory_order success,
0863 memory_order failure);
0864 // Hash support
0865 template <class T> struct hash;
0866 template <class T, class D> struct hash<unique_ptr<T, D> >;
0867 template <class T> struct hash<shared_ptr<T> >;
0868
0869 template <class T, class Alloc>
0870 inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
0871
0872 // [allocator.uses.construction], uses-allocator construction
0873 template<class T, class Alloc, class... Args>
0874 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++20
0875 Args&&... args) noexcept;
0876 template<class T, class Alloc, class Tuple1, class Tuple2>
0877 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++20
0878 piecewise_construct_t,
0879 Tuple1&& x, Tuple2&& y) noexcept;
0880 template<class T, class Alloc>
0881 constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept; // since C++20
0882 template<class T, class Alloc, class U, class V>
0883 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++20
0884 U&& u, V&& v) noexcept;
0885 template<class T, class Alloc, class U, class V>
0886 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++23
0887 pair<U, V>& pr) noexcept;
0888 template<class T, class Alloc, class U, class V>
0889 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++20
0890 const pair<U, V>& pr) noexcept;
0891 template<class T, class Alloc, class U, class V>
0892 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++20
0893 pair<U, V>&& pr) noexcept;
0894 template<class T, class Alloc, class U, class V>
0895 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++23
0896 const pair<U, V>&& pr) noexcept;
0897 template<class T, class Alloc, pair-like P>
0898 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++20
0899 P&& p) noexcept;
0900 template<class T, class Alloc, class U>
0901 constexpr auto uses_allocator_construction_args(const Alloc& alloc, // since C++20
0902 U&& u) noexcept;
0903 template<class T, class Alloc, class... Args>
0904 constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args); // since C++20
0905 template<class T, class Alloc, class... Args>
0906 constexpr T* uninitialized_construct_using_allocator(T* p, // since C++20
0907 const Alloc& alloc, Args&&... args);
0908
0909 // [ptr.align]
0910 void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
0911
0912 template<size_t N, class T>
0913 [[nodiscard]] constexpr T* assume_aligned(T* ptr); // since C++20
0914
0915 // [out.ptr.t], class template out_ptr_t
0916 template<class Smart, class Pointer, class... Args>
0917 class out_ptr_t; // since c++23
0918
0919 // [out.ptr], function template out_ptr
0920 template<class Pointer = void, class Smart, class... Args>
0921 auto out_ptr(Smart& s, Args&&... args); // since c++23
0922
0923 // [inout.ptr.t], class template inout_ptr_t
0924 template<class Smart, class Pointer, class... Args>
0925 class inout_ptr_t; // since c++23
0926
0927 // [inout.ptr], function template inout_ptr
0928 template<class Pointer = void, class Smart, class... Args>
0929 auto inout_ptr(Smart& s, Args&&... args); // since c++23
0930
0931 } // std
0932
0933 */
0934
0935 // clang-format on
0936
0937 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0938 # include <__cxx03/memory>
0939 #else
0940 # include <__config>
0941 # include <__memory/addressof.h>
0942 # include <__memory/align.h>
0943 # include <__memory/allocator.h>
0944 # include <__memory/allocator_arg_t.h>
0945 # include <__memory/allocator_traits.h>
0946 # include <__memory/auto_ptr.h>
0947 # include <__memory/inout_ptr.h>
0948 # include <__memory/out_ptr.h>
0949 # include <__memory/pointer_traits.h>
0950 # include <__memory/raw_storage_iterator.h>
0951 # include <__memory/shared_ptr.h>
0952 # include <__memory/temporary_buffer.h>
0953 # include <__memory/uninitialized_algorithms.h>
0954 # include <__memory/unique_ptr.h>
0955 # include <__memory/uses_allocator.h>
0956
0957 // standard-mandated includes
0958
0959 # if _LIBCPP_STD_VER >= 17
0960 # include <__memory/construct_at.h>
0961 # endif
0962
0963 # if _LIBCPP_STD_VER >= 20
0964 # include <__memory/assume_aligned.h>
0965 # include <__memory/concepts.h>
0966 # include <__memory/ranges_construct_at.h>
0967 # include <__memory/ranges_uninitialized_algorithms.h>
0968 # include <__memory/uses_allocator_construction.h>
0969 # endif
0970
0971 # if _LIBCPP_STD_VER >= 23
0972 # include <__memory/allocate_at_least.h>
0973 # endif
0974
0975 # include <version>
0976
0977 // [memory.syn]
0978 # include <compare>
0979
0980 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0981 # pragma GCC system_header
0982 # endif
0983
0984 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0985 # include <atomic>
0986 # include <concepts>
0987 # include <cstddef>
0988 # include <cstdint>
0989 # include <cstdlib>
0990 # include <cstring>
0991 # include <iosfwd>
0992 # include <iterator>
0993 # include <new>
0994 # include <stdexcept>
0995 # include <tuple>
0996 # include <type_traits>
0997 # include <typeinfo>
0998 # include <utility>
0999 # endif
1000 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1001
1002 #endif // _LIBCPP_MEMORY