146035553Spatrick// -*- C++ -*- 2*4bdff4beSrobert//===----------------------------------------------------------------------===// 346035553Spatrick// 446035553Spatrick// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 546035553Spatrick// See https://llvm.org/LICENSE.txt for license information. 646035553Spatrick// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 746035553Spatrick// 846035553Spatrick//===----------------------------------------------------------------------===// 946035553Spatrick 1046035553Spatrick#ifndef _LIBCPP_MEMORY 1146035553Spatrick#define _LIBCPP_MEMORY 1246035553Spatrick 1346035553Spatrick/* 1446035553Spatrick memory synopsis 1546035553Spatrick 1646035553Spatricknamespace std 1746035553Spatrick{ 1846035553Spatrick 1946035553Spatrickstruct allocator_arg_t { }; 2046035553Spatrickinline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); 2146035553Spatrick 2246035553Spatricktemplate <class T, class Alloc> struct uses_allocator; 2346035553Spatrick 2446035553Spatricktemplate <class Ptr> 2546035553Spatrickstruct pointer_traits 2646035553Spatrick{ 2746035553Spatrick typedef Ptr pointer; 2846035553Spatrick typedef <details> element_type; 2946035553Spatrick typedef <details> difference_type; 3046035553Spatrick 3146035553Spatrick template <class U> using rebind = <details>; 3246035553Spatrick 3346035553Spatrick static pointer pointer_to(<details>); 3446035553Spatrick}; 3546035553Spatrick 3646035553Spatricktemplate <class T> 3746035553Spatrickstruct pointer_traits<T*> 3846035553Spatrick{ 3946035553Spatrick typedef T* pointer; 4046035553Spatrick typedef T element_type; 4146035553Spatrick typedef ptrdiff_t difference_type; 4246035553Spatrick 4346035553Spatrick template <class U> using rebind = U*; 4446035553Spatrick 4546035553Spatrick static pointer pointer_to(<details>) noexcept; // constexpr in C++20 4646035553Spatrick}; 4746035553Spatrick 4846035553Spatricktemplate <class T> constexpr T* to_address(T* p) noexcept; // C++20 4976d0caaeSpatricktemplate <class Ptr> constexpr auto to_address(const Ptr& p) noexcept; // C++20 5046035553Spatrick 5146035553Spatricktemplate <class Alloc> 5246035553Spatrickstruct allocator_traits 5346035553Spatrick{ 5446035553Spatrick typedef Alloc allocator_type; 5546035553Spatrick typedef typename allocator_type::value_type 5646035553Spatrick value_type; 5746035553Spatrick 5846035553Spatrick typedef Alloc::pointer | value_type* pointer; 5946035553Spatrick typedef Alloc::const_pointer 6046035553Spatrick | pointer_traits<pointer>::rebind<const value_type> 6146035553Spatrick const_pointer; 6246035553Spatrick typedef Alloc::void_pointer 6346035553Spatrick | pointer_traits<pointer>::rebind<void> 6446035553Spatrick void_pointer; 6546035553Spatrick typedef Alloc::const_void_pointer 6646035553Spatrick | pointer_traits<pointer>::rebind<const void> 6746035553Spatrick const_void_pointer; 6846035553Spatrick typedef Alloc::difference_type 6946035553Spatrick | pointer_traits<pointer>::difference_type 7046035553Spatrick difference_type; 7146035553Spatrick typedef Alloc::size_type 7246035553Spatrick | make_unsigned<difference_type>::type 7346035553Spatrick size_type; 7446035553Spatrick typedef Alloc::propagate_on_container_copy_assignment 7546035553Spatrick | false_type propagate_on_container_copy_assignment; 7646035553Spatrick typedef Alloc::propagate_on_container_move_assignment 7746035553Spatrick | false_type propagate_on_container_move_assignment; 7846035553Spatrick typedef Alloc::propagate_on_container_swap 7946035553Spatrick | false_type propagate_on_container_swap; 8046035553Spatrick typedef Alloc::is_always_equal 8146035553Spatrick | is_empty is_always_equal; 8246035553Spatrick 83037e7968Spatrick template <class T> using rebind_alloc = Alloc::rebind<T>::other | Alloc<T, Args...>; 8446035553Spatrick template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; 8546035553Spatrick 8676d0caaeSpatrick static pointer allocate(allocator_type& a, size_type n); // constexpr and [[nodiscard]] in C++20 8776d0caaeSpatrick static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // constexpr and [[nodiscard]] in C++20 8846035553Spatrick 8976d0caaeSpatrick static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; // constexpr in C++20 9046035553Spatrick 9146035553Spatrick template <class T, class... Args> 9276d0caaeSpatrick static void construct(allocator_type& a, T* p, Args&&... args); // constexpr in C++20 9346035553Spatrick 9446035553Spatrick template <class T> 9576d0caaeSpatrick static void destroy(allocator_type& a, T* p); // constexpr in C++20 9646035553Spatrick 9776d0caaeSpatrick static size_type max_size(const allocator_type& a); // noexcept in C++14, constexpr in C++20 9876d0caaeSpatrick static allocator_type select_on_container_copy_construction(const allocator_type& a); // constexpr in C++20 9946035553Spatrick}; 10046035553Spatrick 101*4bdff4beSroberttemplate<class Pointer> 102*4bdff4beSrobertstruct allocation_result { 103*4bdff4beSrobert Pointer ptr; 104*4bdff4beSrobert size_t count; 105*4bdff4beSrobert}; // since C++23 106*4bdff4beSrobert 107*4bdff4beSroberttemplate<class Allocator> 108*4bdff4beSrobert[[nodiscard]] constexpr allocation_result<typename allocator_traits<Allocator>::pointer> 109*4bdff4beSrobert allocate_at_least(Allocator& a, size_t n); // since C++23 110*4bdff4beSrobert 11146035553Spatricktemplate <> 11276d0caaeSpatrickclass allocator<void> // removed in C++20 11346035553Spatrick{ 11446035553Spatrickpublic: 11546035553Spatrick typedef void* pointer; 11646035553Spatrick typedef const void* const_pointer; 11746035553Spatrick typedef void value_type; 11846035553Spatrick 11946035553Spatrick template <class _Up> struct rebind {typedef allocator<_Up> other;}; 12046035553Spatrick}; 12146035553Spatrick 12246035553Spatricktemplate <class T> 12346035553Spatrickclass allocator 12446035553Spatrick{ 12546035553Spatrickpublic: 12676d0caaeSpatrick typedef size_t size_type; 12776d0caaeSpatrick typedef ptrdiff_t difference_type; 128037e7968Spatrick typedef T* pointer; // deprecated in C++17, removed in C++20 129037e7968Spatrick typedef const T* const_pointer; // deprecated in C++17, removed in C++20 130037e7968Spatrick typedef typename add_lvalue_reference<T>::type 131037e7968Spatrick reference; // deprecated in C++17, removed in C++20 132037e7968Spatrick typedef typename add_lvalue_reference<const T>::type 133037e7968Spatrick const_reference; // deprecated in C++17, removed in C++20 134037e7968Spatrick 13546035553Spatrick typedef T value_type; 13646035553Spatrick 137037e7968Spatrick template <class U> struct rebind {typedef allocator<U> other;}; // deprecated in C++17, removed in C++20 138037e7968Spatrick 139037e7968Spatrick typedef true_type propagate_on_container_move_assignment; 140037e7968Spatrick typedef true_type is_always_equal; 14146035553Spatrick 14246035553Spatrick constexpr allocator() noexcept; // constexpr in C++20 14346035553Spatrick constexpr allocator(const allocator&) noexcept; // constexpr in C++20 14446035553Spatrick template <class U> 14546035553Spatrick constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20 14676d0caaeSpatrick ~allocator(); // constexpr in C++20 147037e7968Spatrick pointer address(reference x) const noexcept; // deprecated in C++17, removed in C++20 148037e7968Spatrick const_pointer address(const_reference x) const noexcept; // deprecated in C++17, removed in C++20 149037e7968Spatrick T* allocate(size_t n, const void* hint); // deprecated in C++17, removed in C++20 15076d0caaeSpatrick T* allocate(size_t n); // constexpr in C++20 15176d0caaeSpatrick void deallocate(T* p, size_t n) noexcept; // constexpr in C++20 152037e7968Spatrick size_type max_size() const noexcept; // deprecated in C++17, removed in C++20 15346035553Spatrick template<class U, class... Args> 154037e7968Spatrick void construct(U* p, Args&&... args); // deprecated in C++17, removed in C++20 15546035553Spatrick template <class U> 156037e7968Spatrick void destroy(U* p); // deprecated in C++17, removed in C++20 15746035553Spatrick}; 15846035553Spatrick 15946035553Spatricktemplate <class T, class U> 16076d0caaeSpatrickbool operator==(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20 16146035553Spatrick 16246035553Spatricktemplate <class T, class U> 16376d0caaeSpatrickbool operator!=(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20 16446035553Spatrick 16546035553Spatricktemplate <class OutputIterator, class T> 16676d0caaeSpatrickclass raw_storage_iterator // deprecated in C++17, removed in C++20 16776d0caaeSpatrick : public iterator<output_iterator_tag, void, void, void, void> // until C++17 16846035553Spatrick{ 16946035553Spatrickpublic: 17076d0caaeSpatrick typedef output_iterator_tag iterator_category; 17176d0caaeSpatrick typedef void value_type; 17276d0caaeSpatrick typedef void difference_type; // until C++20 17376d0caaeSpatrick typedef ptrdiff_t difference_type; // since C++20 17476d0caaeSpatrick typedef void pointer; 17576d0caaeSpatrick typedef void reference; 17676d0caaeSpatrick 17746035553Spatrick explicit raw_storage_iterator(OutputIterator x); 17846035553Spatrick raw_storage_iterator& operator*(); 17946035553Spatrick raw_storage_iterator& operator=(const T& element); 18046035553Spatrick raw_storage_iterator& operator++(); 18146035553Spatrick raw_storage_iterator operator++(int); 18246035553Spatrick}; 18346035553Spatrick 18446035553Spatricktemplate <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; 18546035553Spatricktemplate <class T> void return_temporary_buffer(T* p) noexcept; 18646035553Spatrick 18746035553Spatricktemplate <class T> T* addressof(T& r) noexcept; 18846035553Spatricktemplate <class T> T* addressof(const T&& r) noexcept = delete; 18946035553Spatrick 19046035553Spatricktemplate <class InputIterator, class ForwardIterator> 19146035553SpatrickForwardIterator 19246035553Spatrickuninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); 19346035553Spatrick 194*4bdff4beSrobertnamespace ranges { 195*4bdff4beSrobert 196*4bdff4beSroberttemplate<class InputIterator, class OutputIterator> 197*4bdff4beSrobertusing uninitialized_copy_result = in_out_result<InputIterator, OutputIterator>; // since C++20 198*4bdff4beSrobert 199*4bdff4beSroberttemplate<input_iterator InputIterator, sentinel-for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel2> 200*4bdff4beSrobert requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>> 201*4bdff4beSrobertuninitialized_copy_result<InputIterator, OutputIterator> 202*4bdff4beSrobertuninitialized_copy(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20 203*4bdff4beSrobert 204*4bdff4beSroberttemplate<input_range InputRange, nothrow-forward-range OutputRange> 205*4bdff4beSrobert requires constructible_from<range_value_t<OutputRange>, range_reference_t<InputRange>> 206*4bdff4beSrobertuninitialized_copy_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>> 207*4bdff4beSrobertuninitialized_copy(InputRange&& in_range, OutputRange&& out_range); // since C++20 208*4bdff4beSrobert 209*4bdff4beSrobert} 210*4bdff4beSrobert 21146035553Spatricktemplate <class InputIterator, class Size, class ForwardIterator> 21246035553SpatrickForwardIterator 21346035553Spatrickuninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); 21446035553Spatrick 215*4bdff4beSrobertnamespace ranges { 216*4bdff4beSrobert 217*4bdff4beSroberttemplate<class InputIterator, class OutputIterator> 218*4bdff4beSrobertusing uninitialized_copy_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20 219*4bdff4beSrobert 220*4bdff4beSroberttemplate<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel> 221*4bdff4beSrobert requires constructible_from<iter_value_t<OutputIterator>, iter_reference_t<InputIterator>> 222*4bdff4beSrobertuninitialized_copy_n_result<InputIterator, OutputIterator> 223*4bdff4beSrobertuninitialized_copy_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20 224*4bdff4beSrobert 225*4bdff4beSrobert} 226*4bdff4beSrobert 22746035553Spatricktemplate <class ForwardIterator, class T> 22846035553Spatrickvoid uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); 22946035553Spatrick 230*4bdff4beSrobertnamespace ranges { 231*4bdff4beSrobert 232*4bdff4beSroberttemplate <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel, class T> 233*4bdff4beSrobert requires constructible_from<iter_value_t<ForwardIterator>, const T&> 234*4bdff4beSrobertForwardIterator uninitialized_fill(ForwardIterator first, Sentinel last, const T& x); // since C++20 235*4bdff4beSrobert 236*4bdff4beSroberttemplate <nothrow-forward-range ForwardRange, class T> 237*4bdff4beSrobert requires constructible_from<range_value_t<ForwardRange>, const T&> 238*4bdff4beSrobertborrowed_iterator_t<ForwardRange> uninitialized_fill(ForwardRange&& range, const T& x); // since C++20 239*4bdff4beSrobert 240*4bdff4beSrobert} 241*4bdff4beSrobert 24246035553Spatricktemplate <class ForwardIterator, class Size, class T> 24346035553SpatrickForwardIterator 24446035553Spatrickuninitialized_fill_n(ForwardIterator first, Size n, const T& x); 24546035553Spatrick 246*4bdff4beSrobertnamespace ranges { 247*4bdff4beSrobert 248*4bdff4beSroberttemplate <nothrow-forward-iterator ForwardIterator, class T> 249*4bdff4beSrobert requires constructible_from<iter_value_t<ForwardIterator>, const T&> 250*4bdff4beSrobertForwardIterator uninitialized_fill_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 251*4bdff4beSrobert 252*4bdff4beSrobert} 253*4bdff4beSrobert 25476d0caaeSpatricktemplate <class T, class ...Args> 25576d0caaeSpatrickconstexpr T* construct_at(T* location, Args&& ...args); // since C++20 25676d0caaeSpatrick 257*4bdff4beSrobertnamespace ranges { 258*4bdff4beSrobert template<class T, class... Args> 259*4bdff4beSrobert constexpr T* construct_at(T* location, Args&&... args); // since C++20 260*4bdff4beSrobert} 261*4bdff4beSrobert 26246035553Spatricktemplate <class T> 26376d0caaeSpatrickvoid destroy_at(T* location); // constexpr in C++20 26446035553Spatrick 265*4bdff4beSrobertnamespace ranges { 266*4bdff4beSrobert template<destructible T> 267*4bdff4beSrobert constexpr void destroy_at(T* location) noexcept; // since C++20 268*4bdff4beSrobert} 269*4bdff4beSrobert 27046035553Spatricktemplate <class ForwardIterator> 27176d0caaeSpatrickvoid destroy(ForwardIterator first, ForwardIterator last); // constexpr in C++20 27246035553Spatrick 273*4bdff4beSrobertnamespace ranges { 274*4bdff4beSrobert template<nothrow-input-iterator InputIterator, nothrow-sentinel-for<InputIterator> Sentinel> 275*4bdff4beSrobert requires destructible<iter_value_t<InputIterator>> 276*4bdff4beSrobert constexpr InputIterator destroy(InputIterator first, Sentinel last) noexcept; // since C++20 277*4bdff4beSrobert template<nothrow-input-range InputRange> 278*4bdff4beSrobert requires destructible<range_value_t<InputRange>> 279*4bdff4beSrobert constexpr borrowed_iterator_t<InputRange> destroy(InputRange&& range) noexcept; // since C++20 280*4bdff4beSrobert} 281*4bdff4beSrobert 28246035553Spatricktemplate <class ForwardIterator, class Size> 28376d0caaeSpatrickForwardIterator destroy_n(ForwardIterator first, Size n); // constexpr in C++20 28446035553Spatrick 285*4bdff4beSrobertnamespace ranges { 286*4bdff4beSrobert template<nothrow-input-iterator InputIterator> 287*4bdff4beSrobert requires destructible<iter_value_t<InputIterator>> 288*4bdff4beSrobert constexpr InputIterator destroy_n(InputIterator first, iter_difference_t<InputIterator> n) noexcept; // since C++20 289*4bdff4beSrobert} 290*4bdff4beSrobert 29146035553Spatricktemplate <class InputIterator, class ForwardIterator> 29246035553Spatrick ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result); 29346035553Spatrick 294*4bdff4beSrobertnamespace ranges { 295*4bdff4beSrobert 296*4bdff4beSroberttemplate<class InputIterator, class OutputIterator> 297*4bdff4beSrobertusing uninitialized_move_result = in_out_result<InputIterator, OutputIterator>; // since C++20 298*4bdff4beSrobert 299*4bdff4beSroberttemplate <input_iterator InputIterator, sentinel_for<InputIterator> Sentinel1, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<O> Sentinel2> 300*4bdff4beSrobert requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>> 301*4bdff4beSrobertuninitialized_move_result<InputIterator, OutputIterator> 302*4bdff4beSrobertuninitialized_move(InputIterator ifirst, Sentinel1 ilast, OutputIterator ofirst, Sentinel2 olast); // since C++20 303*4bdff4beSrobert 304*4bdff4beSroberttemplate<input_range InputRange, nothrow-forward-range OutputRange> 305*4bdff4beSrobert requires constructible_from<range_value_t<OutputRange>, range_rvalue_reference_t<InputRange>> 306*4bdff4beSrobertuninitialized_move_result<borrowed_iterator_t<InputRange>, borrowed_iterator_t<OutputRange>> 307*4bdff4beSrobertuninitialized_move(InputRange&& in_range, OutputRange&& out_range); // since C++20 308*4bdff4beSrobert 309*4bdff4beSrobert} 310*4bdff4beSrobert 31146035553Spatricktemplate <class InputIterator, class Size, class ForwardIterator> 31246035553Spatrick pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result); 31346035553Spatrick 314*4bdff4beSrobertnamespace ranges { 315*4bdff4beSrobert 316*4bdff4beSroberttemplate<class InputIterator, class OutputIterator> 317*4bdff4beSrobertusing uninitialized_move_n_result = in_out_result<InputIterator, OutputIterator>; // since C++20 318*4bdff4beSrobert 319*4bdff4beSroberttemplate<input_iterator InputIterator, nothrow-forward-iterator OutputIterator, nothrow-sentinel-for<OutputIterator> Sentinel> 320*4bdff4beSrobert requires constructible_from<iter_value_t<OutputIterator>, iter_rvalue_reference_t<InputIterator>> 321*4bdff4beSrobertuninitialized_move_n_result<InputIterator, OutputIterator> 322*4bdff4beSrobertuninitialized_move_n(InputIterator ifirst, iter_difference_t<InputIterator> n, OutputIterator ofirst, Sentinel olast); // since C++20 323*4bdff4beSrobert 324*4bdff4beSrobert} 325*4bdff4beSrobert 32646035553Spatricktemplate <class ForwardIterator> 32746035553Spatrick void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); 32846035553Spatrick 329*4bdff4beSrobertnamespace ranges { 330*4bdff4beSrobert 331*4bdff4beSroberttemplate <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel> 332*4bdff4beSrobert requires default_initializable<iter_value_t<ForwardIterator>> 333*4bdff4beSrobert ForwardIterator uninitialized_value_construct(ForwardIterator first, Sentinel last); // since C++20 334*4bdff4beSrobert 335*4bdff4beSroberttemplate <nothrow-forward-range ForwardRange> 336*4bdff4beSrobert requires default_initializable<range_value_t<ForwardRange>> 337*4bdff4beSrobert borrowed_iterator_t<ForwardRange> uninitialized_value_construct(ForwardRange&& r); // since C++20 338*4bdff4beSrobert 339*4bdff4beSrobert} 340*4bdff4beSrobert 34146035553Spatricktemplate <class ForwardIterator, class Size> 34246035553Spatrick ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); 34346035553Spatrick 344*4bdff4beSrobertnamespace ranges { 345*4bdff4beSrobert 346*4bdff4beSroberttemplate <nothrow-forward-iterator ForwardIterator> 347*4bdff4beSrobert requires default_initializable<iter_value_t<ForwardIterator>> 348*4bdff4beSrobert ForwardIterator uninitialized_value_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 349*4bdff4beSrobert 350*4bdff4beSrobert} 351*4bdff4beSrobert 35246035553Spatricktemplate <class ForwardIterator> 35346035553Spatrick void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); 35446035553Spatrick 355*4bdff4beSrobertnamespace ranges { 356*4bdff4beSrobert 357*4bdff4beSroberttemplate <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel> 358*4bdff4beSrobert requires default_initializable<iter_value_t<ForwardIterator>> 359*4bdff4beSrobert ForwardIterator uninitialized_default_construct(ForwardIterator first, Sentinel last); // since C++20 360*4bdff4beSrobert 361*4bdff4beSroberttemplate <nothrow-forward-range ForwardRange> 362*4bdff4beSrobert requires default_initializable<range_value_t<ForwardRange>> 363*4bdff4beSrobert borrowed_iterator_t<ForwardRange> uninitialized_default_construct(ForwardRange&& r); // since C++20 364*4bdff4beSrobert 365*4bdff4beSrobert} 366*4bdff4beSrobert 36746035553Spatricktemplate <class ForwardIterator, class Size> 36846035553Spatrick ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); 36946035553Spatrick 370*4bdff4beSrobertnamespace ranges { 371*4bdff4beSrobert 372*4bdff4beSroberttemplate <nothrow-forward-iterator ForwardIterator> 373*4bdff4beSrobert requires default_initializable<iter_value_t<ForwardIterator>> 374*4bdff4beSrobert ForwardIterator uninitialized_default_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 375*4bdff4beSrobert 376*4bdff4beSrobert} 377*4bdff4beSrobert 37846035553Spatricktemplate <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17 37946035553Spatrick 38046035553Spatricktemplate<class X> 38146035553Spatrickclass auto_ptr // deprecated in C++11, removed in C++17 38246035553Spatrick{ 38346035553Spatrickpublic: 38446035553Spatrick typedef X element_type; 38546035553Spatrick 38646035553Spatrick explicit auto_ptr(X* p =0) throw(); 38746035553Spatrick auto_ptr(auto_ptr&) throw(); 38846035553Spatrick template<class Y> auto_ptr(auto_ptr<Y>&) throw(); 38946035553Spatrick auto_ptr& operator=(auto_ptr&) throw(); 39046035553Spatrick template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); 39146035553Spatrick auto_ptr& operator=(auto_ptr_ref<X> r) throw(); 39246035553Spatrick ~auto_ptr() throw(); 39346035553Spatrick 39446035553Spatrick typename add_lvalue_reference<X>::type operator*() const throw(); 39546035553Spatrick X* operator->() const throw(); 39646035553Spatrick X* get() const throw(); 39746035553Spatrick X* release() throw(); 39846035553Spatrick void reset(X* p =0) throw(); 39946035553Spatrick 40046035553Spatrick auto_ptr(auto_ptr_ref<X>) throw(); 40146035553Spatrick template<class Y> operator auto_ptr_ref<Y>() throw(); 40246035553Spatrick template<class Y> operator auto_ptr<Y>() throw(); 40346035553Spatrick}; 40446035553Spatrick 40546035553Spatricktemplate <class T> 40646035553Spatrickstruct default_delete 40746035553Spatrick{ 40846035553Spatrick constexpr default_delete() noexcept = default; 409*4bdff4beSrobert template <class U> constexpr default_delete(const default_delete<U>&) noexcept; // constexpr since C++23 41046035553Spatrick 411*4bdff4beSrobert constexpr void operator()(T*) const noexcept; // constexpr since C++23 41246035553Spatrick}; 41346035553Spatrick 41446035553Spatricktemplate <class T> 41546035553Spatrickstruct default_delete<T[]> 41646035553Spatrick{ 41746035553Spatrick constexpr default_delete() noexcept = default; 418*4bdff4beSrobert template <class U> constexpr default_delete(const default_delete <U[]>&) noexcept; // constexpr since C++23 419*4bdff4beSrobert constexpr void operator()(T*) const noexcept; // constexpr since C++23 42046035553Spatrick template <class U> void operator()(U*) const = delete; 42146035553Spatrick}; 42246035553Spatrick 42346035553Spatricktemplate <class T, class D = default_delete<T>> 42446035553Spatrickclass unique_ptr 42546035553Spatrick{ 42646035553Spatrickpublic: 42746035553Spatrick typedef see below pointer; 42846035553Spatrick typedef T element_type; 42946035553Spatrick typedef D deleter_type; 43046035553Spatrick 43146035553Spatrick // constructors 43246035553Spatrick constexpr unique_ptr() noexcept; 433*4bdff4beSrobert constexpr explicit unique_ptr(pointer p) noexcept; // constexpr since C++23 434*4bdff4beSrobert constexpr unique_ptr(pointer p, see below d1) noexcept; // constexpr since C++23 435*4bdff4beSrobert constexpr unique_ptr(pointer p, see below d2) noexcept; // constexpr since C++23 436*4bdff4beSrobert constexpr unique_ptr(unique_ptr&& u) noexcept; // constexpr since C++23 437*4bdff4beSrobert constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } 43846035553Spatrick template <class U, class E> 439*4bdff4beSrobert constexpr unique_ptr(unique_ptr<U, E>&& u) noexcept; // constexpr since C++23 44046035553Spatrick template <class U> 44146035553Spatrick unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17 44246035553Spatrick 44346035553Spatrick // destructor 444*4bdff4beSrobert constexpr ~unique_ptr(); // constexpr since C++23 44546035553Spatrick 44646035553Spatrick // assignment 447*4bdff4beSrobert constexpr unique_ptr& operator=(unique_ptr&& u) noexcept; // constexpr since C++23 448*4bdff4beSrobert template <class U, class E> 449*4bdff4beSrobert constexpr unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; // constexpr since C++23 450*4bdff4beSrobert constexpr unique_ptr& operator=(nullptr_t) noexcept; // constexpr since C++23 45146035553Spatrick 45246035553Spatrick // observers 453*4bdff4beSrobert typename constexpr add_lvalue_reference<T>::type operator*() const; // constexpr since C++23 454*4bdff4beSrobert constexpr pointer operator->() const noexcept; // constexpr since C++23 455*4bdff4beSrobert constexpr pointer get() const noexcept; // constexpr since C++23 456*4bdff4beSrobert constexpr deleter_type& get_deleter() noexcept; // constexpr since C++23 457*4bdff4beSrobert constexpr const deleter_type& get_deleter() const noexcept; // constexpr since C++23 458*4bdff4beSrobert constexpr explicit operator bool() const noexcept; // constexpr since C++23 45946035553Spatrick 46046035553Spatrick // modifiers 461*4bdff4beSrobert constexpr pointer release() noexcept; // constexpr since C++23 462*4bdff4beSrobert constexpr void reset(pointer p = pointer()) noexcept; // constexpr since C++23 463*4bdff4beSrobert constexpr void swap(unique_ptr& u) noexcept; // constexpr since C++23 46446035553Spatrick}; 46546035553Spatrick 46646035553Spatricktemplate <class T, class D> 46746035553Spatrickclass unique_ptr<T[], D> 46846035553Spatrick{ 46946035553Spatrickpublic: 47046035553Spatrick typedef implementation-defined pointer; 47146035553Spatrick typedef T element_type; 47246035553Spatrick typedef D deleter_type; 47346035553Spatrick 47446035553Spatrick // constructors 47546035553Spatrick constexpr unique_ptr() noexcept; 476*4bdff4beSrobert constexpr explicit unique_ptr(pointer p) noexcept; // constexpr since C++23 477*4bdff4beSrobert constexpr unique_ptr(pointer p, see below d) noexcept; // constexpr since C++23 478*4bdff4beSrobert constexpr unique_ptr(pointer p, see below d) noexcept; // constexpr since C++23 479*4bdff4beSrobert constexpr unique_ptr(unique_ptr&& u) noexcept; // constexpr since C++23 480*4bdff4beSrobert template <class U, class E> 481*4bdff4beSrobert constexpr unique_ptr(unique_ptr <U, E>&& u) noexcept; // constexpr since C++23 482*4bdff4beSrobert constexpr unique_ptr(nullptr_t) noexcept : unique_ptr() { } 48346035553Spatrick 48446035553Spatrick // destructor 485*4bdff4beSrobert constexpr ~unique_ptr(); // constexpr since C++23 48646035553Spatrick 48746035553Spatrick // assignment 488*4bdff4beSrobert constexpr unique_ptr& operator=(unique_ptr&& u) noexcept; // constexpr since C++23 489*4bdff4beSrobert template <class U, class E> 490*4bdff4beSrobert constexpr unique_ptr& operator=(unique_ptr <U, E>&& u) noexcept; // constexpr since C++23 491*4bdff4beSrobert constexpr unique_ptr& operator=(nullptr_t) noexcept; // constexpr since C++23 49246035553Spatrick 49346035553Spatrick // observers 494*4bdff4beSrobert constexpr T& operator[](size_t i) const; // constexpr since C++23 495*4bdff4beSrobert constexpr pointer get() const noexcept; // constexpr since C++23 496*4bdff4beSrobert constexpr deleter_type& get_deleter() noexcept; // constexpr since C++23 497*4bdff4beSrobert constexpr const deleter_type& get_deleter() const noexcept; // constexpr since C++23 498*4bdff4beSrobert constexpr explicit operator bool() const noexcept; // constexpr since C++23 49946035553Spatrick 50046035553Spatrick // modifiers 501*4bdff4beSrobert constexpr pointer release() noexcept; // constexpr since C++23 502*4bdff4beSrobert constexpr void reset(pointer p = pointer()) noexcept; // constexpr since C++23 503*4bdff4beSrobert constexpr void reset(nullptr_t) noexcept; // constexpr since C++23 50446035553Spatrick template <class U> void reset(U) = delete; 505*4bdff4beSrobert constexpr void swap(unique_ptr& u) noexcept; // constexpr since C++23 50646035553Spatrick}; 50746035553Spatrick 50846035553Spatricktemplate <class T, class D> 509*4bdff4beSrobert constexpr void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; // constexpr since C++23 51046035553Spatrick 51146035553Spatricktemplate <class T1, class D1, class T2, class D2> 512*4bdff4beSrobert constexpr bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); // constexpr since C++23 51346035553Spatricktemplate <class T1, class D1, class T2, class D2> 514*4bdff4beSrobert bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); // removed in C++20 51546035553Spatricktemplate <class T1, class D1, class T2, class D2> 51646035553Spatrick bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 51746035553Spatricktemplate <class T1, class D1, class T2, class D2> 51846035553Spatrick bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 51946035553Spatricktemplate <class T1, class D1, class T2, class D2> 52046035553Spatrick bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 52146035553Spatricktemplate <class T1, class D1, class T2, class D2> 52246035553Spatrick bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 523*4bdff4beSroberttemplate<class T1, class D1, class T2, class D2> 524*4bdff4beSrobert requires three_way_comparable_with<typename unique_ptr<T1, D1>::pointer, 525*4bdff4beSrobert typename unique_ptr<T2, D2>::pointer> 526*4bdff4beSrobert compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer, 527*4bdff4beSrobert typename unique_ptr<T2, D2>::pointer> 528*4bdff4beSrobert operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); // C++20 52946035553Spatrick 53046035553Spatricktemplate <class T, class D> 531*4bdff4beSrobert constexpr bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; // constexpr since C++23 53246035553Spatricktemplate <class T, class D> 533*4bdff4beSrobert bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; // removed in C++20 53446035553Spatricktemplate <class T, class D> 535*4bdff4beSrobert bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; // removed in C++20 53646035553Spatricktemplate <class T, class D> 537*4bdff4beSrobert bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; // removed in C++20 53846035553Spatrick 53946035553Spatricktemplate <class T, class D> 540*4bdff4beSrobert constexpr bool operator<(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23 54146035553Spatricktemplate <class T, class D> 542*4bdff4beSrobert constexpr bool operator<(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23 54346035553Spatricktemplate <class T, class D> 544*4bdff4beSrobert constexpr bool operator<=(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23 54546035553Spatricktemplate <class T, class D> 546*4bdff4beSrobert constexpr bool operator<=(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23 54746035553Spatricktemplate <class T, class D> 548*4bdff4beSrobert constexpr bool operator>(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23 54946035553Spatricktemplate <class T, class D> 550*4bdff4beSrobert constexpr bool operator>(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23 55146035553Spatricktemplate <class T, class D> 552*4bdff4beSrobert constexpr bool operator>=(const unique_ptr<T, D>& x, nullptr_t); // constexpr since C++23 55346035553Spatricktemplate <class T, class D> 554*4bdff4beSrobert constexpr bool operator>=(nullptr_t, const unique_ptr<T, D>& y); // constexpr since C++23 555*4bdff4beSroberttemplate<class T, class D> 556*4bdff4beSrobert requires three_way_comparable<typename unique_ptr<T, D>::pointer> 557*4bdff4beSrobert compare_three_way_result_t<typename unique_ptr<T, D>::pointer> 558*4bdff4beSrobert constexpr operator<=>(const unique_ptr<T, D>& x, nullptr_t); // C++20, constexpr since C++23 55946035553Spatrick 56046035553Spatrickclass bad_weak_ptr 56146035553Spatrick : public std::exception 56246035553Spatrick{ 56346035553Spatrick bad_weak_ptr() noexcept; 56446035553Spatrick}; 56546035553Spatrick 566*4bdff4beSroberttemplate<class T, class... Args> 567*4bdff4beSrobertconstexpr unique_ptr<T> make_unique(Args&&... args); // C++14, constexpr since C++23 568*4bdff4beSroberttemplate<class T> 569*4bdff4beSrobertconstexpr unique_ptr<T> make_unique(size_t n); // C++14, constexpr since C++23 57046035553Spatricktemplate<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] 57146035553Spatrick 572*4bdff4beSroberttemplate<class T> 573*4bdff4beSrobert constexpr unique_ptr<T> make_unique_for_overwrite(); // T is not array, C++20, constexpr since C++23 574*4bdff4beSroberttemplate<class T> 575*4bdff4beSrobert constexpr unique_ptr<T> make_unique_for_overwrite(size_t n); // T is U[], C++20, constexpr since C++23 576*4bdff4beSroberttemplate<class T, class... Args> 577*4bdff4beSrobert unspecified make_unique_for_overwrite(Args&&...) = delete; // T is U[N], C++20 578*4bdff4beSrobert 57946035553Spatricktemplate<class E, class T, class Y, class D> 58046035553Spatrick basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p); 58146035553Spatrick 58246035553Spatricktemplate<class T> 58346035553Spatrickclass shared_ptr 58446035553Spatrick{ 58546035553Spatrickpublic: 586*4bdff4beSrobert typedef T element_type; // until C++17 587*4bdff4beSrobert typedef remove_extent_t<T> element_type; // since C++17 58846035553Spatrick typedef weak_ptr<T> weak_type; // C++17 58946035553Spatrick 59046035553Spatrick // constructors: 59146035553Spatrick constexpr shared_ptr() noexcept; 59246035553Spatrick template<class Y> explicit shared_ptr(Y* p); 59346035553Spatrick template<class Y, class D> shared_ptr(Y* p, D d); 59446035553Spatrick template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); 59546035553Spatrick template <class D> shared_ptr(nullptr_t p, D d); 59646035553Spatrick template <class D, class A> shared_ptr(nullptr_t p, D d, A a); 59746035553Spatrick template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept; 59846035553Spatrick shared_ptr(const shared_ptr& r) noexcept; 59946035553Spatrick template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept; 60046035553Spatrick shared_ptr(shared_ptr&& r) noexcept; 60146035553Spatrick template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; 60246035553Spatrick template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); 60346035553Spatrick template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17 60446035553Spatrick template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); 60546035553Spatrick shared_ptr(nullptr_t) : shared_ptr() { } 60646035553Spatrick 60746035553Spatrick // destructor: 60846035553Spatrick ~shared_ptr(); 60946035553Spatrick 61046035553Spatrick // assignment: 61146035553Spatrick shared_ptr& operator=(const shared_ptr& r) noexcept; 61246035553Spatrick template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; 61346035553Spatrick shared_ptr& operator=(shared_ptr&& r) noexcept; 61446035553Spatrick template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); 61546035553Spatrick template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17 61646035553Spatrick template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); 61746035553Spatrick 61846035553Spatrick // modifiers: 61946035553Spatrick void swap(shared_ptr& r) noexcept; 62046035553Spatrick void reset() noexcept; 62146035553Spatrick template<class Y> void reset(Y* p); 62246035553Spatrick template<class Y, class D> void reset(Y* p, D d); 62346035553Spatrick template<class Y, class D, class A> void reset(Y* p, D d, A a); 62446035553Spatrick 62546035553Spatrick // observers: 62646035553Spatrick T* get() const noexcept; 62746035553Spatrick T& operator*() const noexcept; 62846035553Spatrick T* operator->() const noexcept; 62946035553Spatrick long use_count() const noexcept; 63046035553Spatrick bool unique() const noexcept; 63146035553Spatrick explicit operator bool() const noexcept; 63246035553Spatrick template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; 63346035553Spatrick template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; 63446035553Spatrick}; 63546035553Spatrick 636037e7968Spatricktemplate<class T> 637037e7968Spatrickshared_ptr(weak_ptr<T>) -> shared_ptr<T>; 638037e7968Spatricktemplate<class T, class D> 639037e7968Spatrickshared_ptr(unique_ptr<T, D>) -> shared_ptr<T>; 640037e7968Spatrick 64146035553Spatrick// shared_ptr comparisons: 64246035553Spatricktemplate<class T, class U> 64346035553Spatrick bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 64446035553Spatricktemplate<class T, class U> 645*4bdff4beSrobert bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20 64646035553Spatricktemplate<class T, class U> 647*4bdff4beSrobert bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20 64846035553Spatricktemplate<class T, class U> 649*4bdff4beSrobert bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20 65046035553Spatricktemplate<class T, class U> 651*4bdff4beSrobert bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20 65246035553Spatricktemplate<class T, class U> 653*4bdff4beSrobert bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // removed in C++20 654*4bdff4beSroberttemplate<class T, class U> 655*4bdff4beSrobert strong_ordering operator<=>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; // C++20 65646035553Spatrick 65746035553Spatricktemplate <class T> 65846035553Spatrick bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; 65946035553Spatricktemplate <class T> 660*4bdff4beSrobert bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20 66146035553Spatricktemplate <class T> 662*4bdff4beSrobert bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20 66346035553Spatricktemplate <class T> 664*4bdff4beSrobert bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20 66546035553Spatricktemplate <class T> 666*4bdff4beSrobert bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20 66746035553Spatricktemplate <class T> 668*4bdff4beSrobert bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20 66946035553Spatricktemplate <class T> 670*4bdff4beSrobert bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20 67146035553Spatricktemplate <class T> 672*4bdff4beSrobert bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20 67346035553Spatricktemplate <class T> 674*4bdff4beSrobert bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20 67546035553Spatricktemplate <class T> 676*4bdff4beSrobert bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20 67746035553Spatricktemplate <class T> 678*4bdff4beSrobert bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; // removed in C++20 67946035553Spatricktemplate <class T> 680*4bdff4beSrobert bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; // removed in C++20 681*4bdff4beSroberttemplate<class T> 682*4bdff4beSrobert strong_ordering operator<=>(shared_ptr<T> const& x, nullptr_t) noexcept; // C++20 68346035553Spatrick 68446035553Spatrick// shared_ptr specialized algorithms: 68546035553Spatricktemplate<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept; 68646035553Spatrick 68746035553Spatrick// shared_ptr casts: 68846035553Spatricktemplate<class T, class U> 68946035553Spatrick shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; 69046035553Spatricktemplate<class T, class U> 69146035553Spatrick shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; 69246035553Spatricktemplate<class T, class U> 69346035553Spatrick shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; 69446035553Spatrick 69546035553Spatrick// shared_ptr I/O: 69646035553Spatricktemplate<class E, class T, class Y> 69746035553Spatrick basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); 69846035553Spatrick 69946035553Spatrick// shared_ptr get_deleter: 70046035553Spatricktemplate<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept; 70146035553Spatrick 70246035553Spatricktemplate<class T, class... Args> 703*4bdff4beSrobert shared_ptr<T> make_shared(Args&&... args); // T is not an array 70446035553Spatricktemplate<class T, class A, class... Args> 705*4bdff4beSrobert shared_ptr<T> allocate_shared(const A& a, Args&&... args); // T is not an array 706*4bdff4beSrobert 707*4bdff4beSroberttemplate<class T> 708*4bdff4beSrobert shared_ptr<T> make_shared(size_t N); // T is U[] (since C++20) 709*4bdff4beSroberttemplate<class T, class A> 710*4bdff4beSrobert shared_ptr<T> allocate_shared(const A& a, size_t N); // T is U[] (since C++20) 711*4bdff4beSrobert 712*4bdff4beSroberttemplate<class T> 713*4bdff4beSrobert shared_ptr<T> make_shared(); // T is U[N] (since C++20) 714*4bdff4beSroberttemplate<class T, class A> 715*4bdff4beSrobert shared_ptr<T> allocate_shared(const A& a); // T is U[N] (since C++20) 716*4bdff4beSrobert 717*4bdff4beSroberttemplate<class T> 718*4bdff4beSrobert shared_ptr<T> make_shared(size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20) 719*4bdff4beSroberttemplate<class T, class A> 720*4bdff4beSrobert shared_ptr<T> allocate_shared(const A& a, size_t N, const remove_extent_t<T>& u); // T is U[] (since C++20) 721*4bdff4beSrobert 722*4bdff4beSroberttemplate<class T> shared_ptr<T> 723*4bdff4beSrobert make_shared(const remove_extent_t<T>& u); // T is U[N] (since C++20) 724*4bdff4beSroberttemplate<class T, class A> 725*4bdff4beSrobert shared_ptr<T> allocate_shared(const A& a, const remove_extent_t<T>& u); // T is U[N] (since C++20) 726*4bdff4beSrobert 727*4bdff4beSroberttemplate<class T> 728*4bdff4beSrobert shared_ptr<T> make_shared_for_overwrite(); // T is not U[], C++20 729*4bdff4beSroberttemplate<class T, class A> 730*4bdff4beSrobert shared_ptr<T> allocate_shared_for_overwrite(const A& a); // T is not U[], C++20 731*4bdff4beSrobert 732*4bdff4beSroberttemplate<class T> 733*4bdff4beSrobert shared_ptr<T> make_shared_for_overwrite(size_t N); // T is U[], C++20 734*4bdff4beSroberttemplate<class T, class A> 735*4bdff4beSrobert shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); // T is U[], C++20 73646035553Spatrick 73746035553Spatricktemplate<class T> 73846035553Spatrickclass weak_ptr 73946035553Spatrick{ 74046035553Spatrickpublic: 741*4bdff4beSrobert typedef T element_type; // until C++17 742*4bdff4beSrobert typedef remove_extent_t<T> element_type; // since C++17 74346035553Spatrick 74446035553Spatrick // constructors 74546035553Spatrick constexpr weak_ptr() noexcept; 74646035553Spatrick template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; 74746035553Spatrick weak_ptr(weak_ptr const& r) noexcept; 74846035553Spatrick template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; 74946035553Spatrick weak_ptr(weak_ptr&& r) noexcept; // C++14 75046035553Spatrick template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14 75146035553Spatrick 75246035553Spatrick // destructor 75346035553Spatrick ~weak_ptr(); 75446035553Spatrick 75546035553Spatrick // assignment 75646035553Spatrick weak_ptr& operator=(weak_ptr const& r) noexcept; 75746035553Spatrick template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; 75846035553Spatrick template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; 75946035553Spatrick weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 76046035553Spatrick template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14 76146035553Spatrick 76246035553Spatrick // modifiers 76346035553Spatrick void swap(weak_ptr& r) noexcept; 76446035553Spatrick void reset() noexcept; 76546035553Spatrick 76646035553Spatrick // observers 76746035553Spatrick long use_count() const noexcept; 76846035553Spatrick bool expired() const noexcept; 76946035553Spatrick shared_ptr<T> lock() const noexcept; 77046035553Spatrick template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; 77146035553Spatrick template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; 77246035553Spatrick}; 77346035553Spatrick 774037e7968Spatricktemplate<class T> 775037e7968Spatrickweak_ptr(shared_ptr<T>) -> weak_ptr<T>; 776037e7968Spatrick 77746035553Spatrick// weak_ptr specialized algorithms: 77846035553Spatricktemplate<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept; 77946035553Spatrick 78046035553Spatrick// class owner_less: 78146035553Spatricktemplate<class T> struct owner_less; 78246035553Spatrick 78346035553Spatricktemplate<class T> 78446035553Spatrickstruct owner_less<shared_ptr<T> > 78546035553Spatrick : binary_function<shared_ptr<T>, shared_ptr<T>, bool> 78646035553Spatrick{ 78746035553Spatrick typedef bool result_type; 78846035553Spatrick bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept; 78946035553Spatrick bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; 79046035553Spatrick bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; 79146035553Spatrick}; 79246035553Spatrick 79346035553Spatricktemplate<class T> 79446035553Spatrickstruct owner_less<weak_ptr<T> > 79546035553Spatrick : binary_function<weak_ptr<T>, weak_ptr<T>, bool> 79646035553Spatrick{ 79746035553Spatrick typedef bool result_type; 79846035553Spatrick bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept; 79946035553Spatrick bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; 80046035553Spatrick bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; 80146035553Spatrick}; 80246035553Spatrick 80346035553Spatricktemplate <> // Added in C++14 80446035553Spatrickstruct owner_less<void> 80546035553Spatrick{ 80646035553Spatrick template <class _Tp, class _Up> 80746035553Spatrick bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; 80846035553Spatrick template <class _Tp, class _Up> 80946035553Spatrick bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; 81046035553Spatrick template <class _Tp, class _Up> 81146035553Spatrick bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; 81246035553Spatrick template <class _Tp, class _Up> 81346035553Spatrick bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; 81446035553Spatrick 81546035553Spatrick typedef void is_transparent; 81646035553Spatrick}; 81746035553Spatrick 81846035553Spatricktemplate<class T> 81946035553Spatrickclass enable_shared_from_this 82046035553Spatrick{ 82146035553Spatrickprotected: 82246035553Spatrick constexpr enable_shared_from_this() noexcept; 82346035553Spatrick enable_shared_from_this(enable_shared_from_this const&) noexcept; 82446035553Spatrick enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; 82546035553Spatrick ~enable_shared_from_this(); 82646035553Spatrickpublic: 82746035553Spatrick shared_ptr<T> shared_from_this(); 82846035553Spatrick shared_ptr<T const> shared_from_this() const; 82946035553Spatrick}; 83046035553Spatrick 83146035553Spatricktemplate<class T> 83246035553Spatrick bool atomic_is_lock_free(const shared_ptr<T>* p); 83346035553Spatricktemplate<class T> 83446035553Spatrick shared_ptr<T> atomic_load(const shared_ptr<T>* p); 83546035553Spatricktemplate<class T> 83646035553Spatrick shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); 83746035553Spatricktemplate<class T> 83846035553Spatrick void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); 83946035553Spatricktemplate<class T> 84046035553Spatrick void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 84146035553Spatricktemplate<class T> 84246035553Spatrick shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); 84346035553Spatricktemplate<class T> 84446035553Spatrick shared_ptr<T> 84546035553Spatrick atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 84646035553Spatricktemplate<class T> 84746035553Spatrick bool 84846035553Spatrick atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 84946035553Spatricktemplate<class T> 85046035553Spatrick bool 85146035553Spatrick atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 85246035553Spatricktemplate<class T> 85346035553Spatrick bool 85446035553Spatrick atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 85546035553Spatrick shared_ptr<T> w, memory_order success, 85646035553Spatrick memory_order failure); 85746035553Spatricktemplate<class T> 85846035553Spatrick bool 85946035553Spatrick atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 86046035553Spatrick shared_ptr<T> w, memory_order success, 86146035553Spatrick memory_order failure); 86246035553Spatrick// Hash support 86346035553Spatricktemplate <class T> struct hash; 86446035553Spatricktemplate <class T, class D> struct hash<unique_ptr<T, D> >; 86546035553Spatricktemplate <class T> struct hash<shared_ptr<T> >; 86646035553Spatrick 86746035553Spatricktemplate <class T, class Alloc> 86846035553Spatrick inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; 86946035553Spatrick 870*4bdff4beSrobert// [ptr.align] 87146035553Spatrickvoid* align(size_t alignment, size_t size, void*& ptr, size_t& space); 87246035553Spatrick 873*4bdff4beSroberttemplate<size_t N, class T> 874*4bdff4beSrobert[[nodiscard]] constexpr T* assume_aligned(T* ptr); // since C++20 875*4bdff4beSrobert 87646035553Spatrick} // std 87746035553Spatrick 87846035553Spatrick*/ 87946035553Spatrick 880*4bdff4beSrobert#include <__assert> // all public C++ headers provide the assertion handler 88146035553Spatrick#include <__config> 88276d0caaeSpatrick#include <__memory/addressof.h> 883*4bdff4beSrobert#include <__memory/align.h> 884*4bdff4beSrobert#include <__memory/allocate_at_least.h> 88576d0caaeSpatrick#include <__memory/allocation_guard.h> 88676d0caaeSpatrick#include <__memory/allocator.h> 88776d0caaeSpatrick#include <__memory/allocator_arg_t.h> 88876d0caaeSpatrick#include <__memory/allocator_traits.h> 889*4bdff4beSrobert#include <__memory/assume_aligned.h> 890*4bdff4beSrobert#include <__memory/auto_ptr.h> 89176d0caaeSpatrick#include <__memory/compressed_pair.h> 892*4bdff4beSrobert#include <__memory/concepts.h> 89376d0caaeSpatrick#include <__memory/construct_at.h> 89476d0caaeSpatrick#include <__memory/pointer_traits.h> 895*4bdff4beSrobert#include <__memory/ranges_construct_at.h> 896*4bdff4beSrobert#include <__memory/ranges_uninitialized_algorithms.h> 89776d0caaeSpatrick#include <__memory/raw_storage_iterator.h> 89876d0caaeSpatrick#include <__memory/shared_ptr.h> 89976d0caaeSpatrick#include <__memory/temporary_buffer.h> 90076d0caaeSpatrick#include <__memory/uninitialized_algorithms.h> 90176d0caaeSpatrick#include <__memory/unique_ptr.h> 90276d0caaeSpatrick#include <__memory/uses_allocator.h> 903*4bdff4beSrobert#include <__memory/uses_allocator_construction.h> 904*4bdff4beSrobert#include <version> 905*4bdff4beSrobert 906*4bdff4beSrobert// standard-mandated includes 907*4bdff4beSrobert 908*4bdff4beSrobert// [memory.syn] 90976d0caaeSpatrick#include <compare> 910*4bdff4beSrobert 911*4bdff4beSrobert#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 912*4bdff4beSrobert# pragma GCC system_header 913*4bdff4beSrobert#endif 914*4bdff4beSrobert 915*4bdff4beSrobert#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 916*4bdff4beSrobert# include <__pstl_memory> 917*4bdff4beSrobert#endif 918*4bdff4beSrobert 919*4bdff4beSrobert#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 920*4bdff4beSrobert# include <concepts> 92146035553Spatrick# include <cstddef> 92246035553Spatrick# include <cstdint> 92346035553Spatrick# include <cstring> 92476d0caaeSpatrick# include <iosfwd> 92576d0caaeSpatrick# include <iterator> 92676d0caaeSpatrick# include <new> 92776d0caaeSpatrick# include <stdexcept> 92876d0caaeSpatrick# include <tuple> 92976d0caaeSpatrick# include <type_traits> 93076d0caaeSpatrick# include <typeinfo> 93176d0caaeSpatrick# include <utility> 93246035553Spatrick#endif 93346035553Spatrick 93446035553Spatrick#endif // _LIBCPP_MEMORY 935