10b57cec5SDimitry Andric// -*- C++ -*- 2349cc55cSDimitry Andric//===----------------------------------------------------------------------===// 30b57cec5SDimitry Andric// 40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information. 60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 70b57cec5SDimitry Andric// 80b57cec5SDimitry Andric//===----------------------------------------------------------------------===// 90b57cec5SDimitry Andric 100b57cec5SDimitry Andric#ifndef _LIBCPP_MEMORY 110b57cec5SDimitry Andric#define _LIBCPP_MEMORY 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric/* 140b57cec5SDimitry Andric memory synopsis 150b57cec5SDimitry Andric 160b57cec5SDimitry Andricnamespace std 170b57cec5SDimitry Andric{ 180b57cec5SDimitry Andric 190b57cec5SDimitry Andricstruct allocator_arg_t { }; 200b57cec5SDimitry Andricinline constexpr allocator_arg_t allocator_arg = allocator_arg_t(); 210b57cec5SDimitry Andric 220b57cec5SDimitry Andrictemplate <class T, class Alloc> struct uses_allocator; 230b57cec5SDimitry Andric 240b57cec5SDimitry Andrictemplate <class Ptr> 250b57cec5SDimitry Andricstruct pointer_traits 260b57cec5SDimitry Andric{ 270b57cec5SDimitry Andric typedef Ptr pointer; 280b57cec5SDimitry Andric typedef <details> element_type; 290b57cec5SDimitry Andric typedef <details> difference_type; 300b57cec5SDimitry Andric 310b57cec5SDimitry Andric template <class U> using rebind = <details>; 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric static pointer pointer_to(<details>); 340b57cec5SDimitry Andric}; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andrictemplate <class T> 370b57cec5SDimitry Andricstruct pointer_traits<T*> 380b57cec5SDimitry Andric{ 390b57cec5SDimitry Andric typedef T* pointer; 400b57cec5SDimitry Andric typedef T element_type; 410b57cec5SDimitry Andric typedef ptrdiff_t difference_type; 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric template <class U> using rebind = U*; 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric static pointer pointer_to(<details>) noexcept; // constexpr in C++20 460b57cec5SDimitry Andric}; 470b57cec5SDimitry Andric 480b57cec5SDimitry Andrictemplate <class T> constexpr T* to_address(T* p) noexcept; // C++20 49e8d8bef9SDimitry Andrictemplate <class Ptr> constexpr auto to_address(const Ptr& p) noexcept; // C++20 500b57cec5SDimitry Andric 510b57cec5SDimitry Andrictemplate <class Alloc> 520b57cec5SDimitry Andricstruct allocator_traits 530b57cec5SDimitry Andric{ 540b57cec5SDimitry Andric typedef Alloc allocator_type; 550b57cec5SDimitry Andric typedef typename allocator_type::value_type 560b57cec5SDimitry Andric value_type; 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric typedef Alloc::pointer | value_type* pointer; 590b57cec5SDimitry Andric typedef Alloc::const_pointer 600b57cec5SDimitry Andric | pointer_traits<pointer>::rebind<const value_type> 610b57cec5SDimitry Andric const_pointer; 620b57cec5SDimitry Andric typedef Alloc::void_pointer 630b57cec5SDimitry Andric | pointer_traits<pointer>::rebind<void> 640b57cec5SDimitry Andric void_pointer; 650b57cec5SDimitry Andric typedef Alloc::const_void_pointer 660b57cec5SDimitry Andric | pointer_traits<pointer>::rebind<const void> 670b57cec5SDimitry Andric const_void_pointer; 680b57cec5SDimitry Andric typedef Alloc::difference_type 690b57cec5SDimitry Andric | pointer_traits<pointer>::difference_type 700b57cec5SDimitry Andric difference_type; 710b57cec5SDimitry Andric typedef Alloc::size_type 720b57cec5SDimitry Andric | make_unsigned<difference_type>::type 730b57cec5SDimitry Andric size_type; 740b57cec5SDimitry Andric typedef Alloc::propagate_on_container_copy_assignment 750b57cec5SDimitry Andric | false_type propagate_on_container_copy_assignment; 760b57cec5SDimitry Andric typedef Alloc::propagate_on_container_move_assignment 770b57cec5SDimitry Andric | false_type propagate_on_container_move_assignment; 780b57cec5SDimitry Andric typedef Alloc::propagate_on_container_swap 790b57cec5SDimitry Andric | false_type propagate_on_container_swap; 800b57cec5SDimitry Andric typedef Alloc::is_always_equal 810b57cec5SDimitry Andric | is_empty is_always_equal; 820b57cec5SDimitry Andric 835ffd83dbSDimitry Andric template <class T> using rebind_alloc = Alloc::rebind<T>::other | Alloc<T, Args...>; 840b57cec5SDimitry Andric template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>; 850b57cec5SDimitry Andric 86e8d8bef9SDimitry Andric static pointer allocate(allocator_type& a, size_type n); // constexpr and [[nodiscard]] in C++20 87e8d8bef9SDimitry Andric static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // constexpr and [[nodiscard]] in C++20 880b57cec5SDimitry Andric 89e8d8bef9SDimitry Andric static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; // constexpr in C++20 900b57cec5SDimitry Andric 910b57cec5SDimitry Andric template <class T, class... Args> 92e8d8bef9SDimitry Andric static void construct(allocator_type& a, T* p, Args&&... args); // constexpr in C++20 930b57cec5SDimitry Andric 940b57cec5SDimitry Andric template <class T> 95e8d8bef9SDimitry Andric static void destroy(allocator_type& a, T* p); // constexpr in C++20 960b57cec5SDimitry Andric 97e8d8bef9SDimitry Andric static size_type max_size(const allocator_type& a); // noexcept in C++14, constexpr in C++20 98e8d8bef9SDimitry Andric static allocator_type select_on_container_copy_construction(const allocator_type& a); // constexpr in C++20 990b57cec5SDimitry Andric}; 1000b57cec5SDimitry Andric 1010b57cec5SDimitry Andrictemplate <> 10223408297SDimitry Andricclass allocator<void> // removed in C++20 1030b57cec5SDimitry Andric{ 1040b57cec5SDimitry Andricpublic: 105fe6060f1SDimitry Andric typedef void* pointer; 106fe6060f1SDimitry Andric typedef const void* const_pointer; 107fe6060f1SDimitry Andric typedef void value_type; 1080b57cec5SDimitry Andric 109fe6060f1SDimitry Andric template <class _Up> struct rebind {typedef allocator<_Up> other;}; 1100b57cec5SDimitry Andric}; 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andrictemplate <class T> 1130b57cec5SDimitry Andricclass allocator 1140b57cec5SDimitry Andric{ 1150b57cec5SDimitry Andricpublic: 116e8d8bef9SDimitry Andric typedef size_t size_type; 117e8d8bef9SDimitry Andric typedef ptrdiff_t difference_type; 1185ffd83dbSDimitry Andric typedef T* pointer; // deprecated in C++17, removed in C++20 1195ffd83dbSDimitry Andric typedef const T* const_pointer; // deprecated in C++17, removed in C++20 1205ffd83dbSDimitry Andric typedef typename add_lvalue_reference<T>::type 1215ffd83dbSDimitry Andric reference; // deprecated in C++17, removed in C++20 1225ffd83dbSDimitry Andric typedef typename add_lvalue_reference<const T>::type 1235ffd83dbSDimitry Andric const_reference; // deprecated in C++17, removed in C++20 1245ffd83dbSDimitry Andric 1250b57cec5SDimitry Andric typedef T value_type; 1260b57cec5SDimitry Andric 1275ffd83dbSDimitry Andric template <class U> struct rebind {typedef allocator<U> other;}; // deprecated in C++17, removed in C++20 1285ffd83dbSDimitry Andric 1295ffd83dbSDimitry Andric typedef true_type propagate_on_container_move_assignment; 1305ffd83dbSDimitry Andric typedef true_type is_always_equal; 1310b57cec5SDimitry Andric 1320b57cec5SDimitry Andric constexpr allocator() noexcept; // constexpr in C++20 1330b57cec5SDimitry Andric constexpr allocator(const allocator&) noexcept; // constexpr in C++20 1340b57cec5SDimitry Andric template <class U> 1350b57cec5SDimitry Andric constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20 136e8d8bef9SDimitry Andric ~allocator(); // constexpr in C++20 1375ffd83dbSDimitry Andric pointer address(reference x) const noexcept; // deprecated in C++17, removed in C++20 1385ffd83dbSDimitry Andric const_pointer address(const_reference x) const noexcept; // deprecated in C++17, removed in C++20 1395ffd83dbSDimitry Andric T* allocate(size_t n, const void* hint); // deprecated in C++17, removed in C++20 140e8d8bef9SDimitry Andric T* allocate(size_t n); // constexpr in C++20 141e8d8bef9SDimitry Andric void deallocate(T* p, size_t n) noexcept; // constexpr in C++20 1425ffd83dbSDimitry Andric size_type max_size() const noexcept; // deprecated in C++17, removed in C++20 1430b57cec5SDimitry Andric template<class U, class... Args> 1445ffd83dbSDimitry Andric void construct(U* p, Args&&... args); // deprecated in C++17, removed in C++20 1450b57cec5SDimitry Andric template <class U> 1465ffd83dbSDimitry Andric void destroy(U* p); // deprecated in C++17, removed in C++20 1470b57cec5SDimitry Andric}; 1480b57cec5SDimitry Andric 1490b57cec5SDimitry Andrictemplate <class T, class U> 150e8d8bef9SDimitry Andricbool operator==(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andrictemplate <class T, class U> 153e8d8bef9SDimitry Andricbool operator!=(const allocator<T>&, const allocator<U>&) noexcept; // constexpr in C++20 1540b57cec5SDimitry Andric 1550b57cec5SDimitry Andrictemplate <class OutputIterator, class T> 156fe6060f1SDimitry Andricclass raw_storage_iterator // deprecated in C++17, removed in C++20 157fe6060f1SDimitry Andric : public iterator<output_iterator_tag, void, void, void, void> // until C++17 1580b57cec5SDimitry Andric{ 1590b57cec5SDimitry Andricpublic: 160fe6060f1SDimitry Andric typedef output_iterator_tag iterator_category; 161fe6060f1SDimitry Andric typedef void value_type; 162fe6060f1SDimitry Andric typedef void difference_type; // until C++20 163fe6060f1SDimitry Andric typedef ptrdiff_t difference_type; // since C++20 164fe6060f1SDimitry Andric typedef void pointer; 165fe6060f1SDimitry Andric typedef void reference; 166fe6060f1SDimitry Andric 1670b57cec5SDimitry Andric explicit raw_storage_iterator(OutputIterator x); 1680b57cec5SDimitry Andric raw_storage_iterator& operator*(); 1690b57cec5SDimitry Andric raw_storage_iterator& operator=(const T& element); 1700b57cec5SDimitry Andric raw_storage_iterator& operator++(); 1710b57cec5SDimitry Andric raw_storage_iterator operator++(int); 1720b57cec5SDimitry Andric}; 1730b57cec5SDimitry Andric 1740b57cec5SDimitry Andrictemplate <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept; 1750b57cec5SDimitry Andrictemplate <class T> void return_temporary_buffer(T* p) noexcept; 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andrictemplate <class T> T* addressof(T& r) noexcept; 1780b57cec5SDimitry Andrictemplate <class T> T* addressof(const T&& r) noexcept = delete; 1790b57cec5SDimitry Andric 1800b57cec5SDimitry Andrictemplate <class InputIterator, class ForwardIterator> 1810b57cec5SDimitry AndricForwardIterator 1820b57cec5SDimitry Andricuninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); 1830b57cec5SDimitry Andric 1840b57cec5SDimitry Andrictemplate <class InputIterator, class Size, class ForwardIterator> 1850b57cec5SDimitry AndricForwardIterator 1860b57cec5SDimitry Andricuninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); 1870b57cec5SDimitry Andric 1880b57cec5SDimitry Andrictemplate <class ForwardIterator, class T> 1890b57cec5SDimitry Andricvoid uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); 1900b57cec5SDimitry Andric 191*0eae32dcSDimitry Andrictemplate <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel, class T> 192*0eae32dcSDimitry Andric requires constructible_from<iter_value_t<ForwardIterator>, const T&> 193*0eae32dcSDimitry AndricForwardIterator ranges::uninitialized_fill(ForwardIterator first, Sentinel last, const T& x); // since C++20 194*0eae32dcSDimitry Andric 195*0eae32dcSDimitry Andrictemplate <nothrow-forward-range ForwardRange, class T> 196*0eae32dcSDimitry Andric requires constructible_from<range_value_t<ForwardRange>, const T&> 197*0eae32dcSDimitry Andricborrowed_iterator_t<ForwardRange> ranges::uninitialized_fill(ForwardRange&& range, const T& x); // since C++20 198*0eae32dcSDimitry Andric 1990b57cec5SDimitry Andrictemplate <class ForwardIterator, class Size, class T> 2000b57cec5SDimitry AndricForwardIterator 2010b57cec5SDimitry Andricuninitialized_fill_n(ForwardIterator first, Size n, const T& x); 2020b57cec5SDimitry Andric 203*0eae32dcSDimitry Andrictemplate <nothrow-forward-iterator ForwardIterator, class T> 204*0eae32dcSDimitry Andric requires constructible_from<iter_value_t<ForwardIterator>, const T&> 205*0eae32dcSDimitry AndricForwardIterator ranges::uninitialized_fill_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 206*0eae32dcSDimitry Andric 207e8d8bef9SDimitry Andrictemplate <class T, class ...Args> 208e8d8bef9SDimitry Andricconstexpr T* construct_at(T* location, Args&& ...args); // since C++20 209e8d8bef9SDimitry Andric 2100b57cec5SDimitry Andrictemplate <class T> 211e8d8bef9SDimitry Andricvoid destroy_at(T* location); // constexpr in C++20 2120b57cec5SDimitry Andric 2130b57cec5SDimitry Andrictemplate <class ForwardIterator> 214e8d8bef9SDimitry Andricvoid destroy(ForwardIterator first, ForwardIterator last); // constexpr in C++20 2150b57cec5SDimitry Andric 2160b57cec5SDimitry Andrictemplate <class ForwardIterator, class Size> 217e8d8bef9SDimitry AndricForwardIterator destroy_n(ForwardIterator first, Size n); // constexpr in C++20 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andrictemplate <class InputIterator, class ForwardIterator> 2200b57cec5SDimitry Andric ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result); 2210b57cec5SDimitry Andric 2220b57cec5SDimitry Andrictemplate <class InputIterator, class Size, class ForwardIterator> 2230b57cec5SDimitry Andric pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result); 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andrictemplate <class ForwardIterator> 2260b57cec5SDimitry Andric void uninitialized_value_construct(ForwardIterator first, ForwardIterator last); 2270b57cec5SDimitry Andric 228*0eae32dcSDimitry Andrictemplate <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel> 229*0eae32dcSDimitry Andric requires default_initializable<iter_value_t<ForwardIterator>> 230*0eae32dcSDimitry Andric ForwardIterator ranges::uninitialized_value_construct(ForwardIterator first, Sentinel last); // since C++20 231*0eae32dcSDimitry Andric 232*0eae32dcSDimitry Andrictemplate <nothrow-forward-range ForwardRange> 233*0eae32dcSDimitry Andric requires default_initializable<range_value_t<ForwardRange>> 234*0eae32dcSDimitry Andric borrowed_iterator_t<ForwardRange> ranges::uninitialized_value_construct(ForwardRange&& r); // since C++20 235*0eae32dcSDimitry Andric 2360b57cec5SDimitry Andrictemplate <class ForwardIterator, class Size> 2370b57cec5SDimitry Andric ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n); 2380b57cec5SDimitry Andric 239*0eae32dcSDimitry Andrictemplate <nothrow-forward-iterator ForwardIterator> 240*0eae32dcSDimitry Andric requires default_initializable<iter_value_t<ForwardIterator>> 241*0eae32dcSDimitry Andric ForwardIterator ranges::uninitialized_value_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 242*0eae32dcSDimitry Andric 2430b57cec5SDimitry Andrictemplate <class ForwardIterator> 2440b57cec5SDimitry Andric void uninitialized_default_construct(ForwardIterator first, ForwardIterator last); 2450b57cec5SDimitry Andric 246*0eae32dcSDimitry Andrictemplate <nothrow-forward-iterator ForwardIterator, nothrow-sentinel-for<ForwardIterator> Sentinel> 247*0eae32dcSDimitry Andric requires default_initializable<iter_value_t<ForwardIterator>> 248*0eae32dcSDimitry Andric ForwardIterator ranges::uninitialized_default_construct(ForwardIterator first, Sentinel last); // since C++20 249*0eae32dcSDimitry Andric 250*0eae32dcSDimitry Andrictemplate <nothrow-forward-range ForwardRange> 251*0eae32dcSDimitry Andric requires default_initializable<range_value_t<ForwardRange>> 252*0eae32dcSDimitry Andric borrowed_iterator_t<ForwardRange> ranges::uninitialized_default_construct(ForwardRange&& r); // since C++20 253*0eae32dcSDimitry Andric 2540b57cec5SDimitry Andrictemplate <class ForwardIterator, class Size> 2550b57cec5SDimitry Andric ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n); 2560b57cec5SDimitry Andric 257*0eae32dcSDimitry Andrictemplate <nothrow-forward-iterator ForwardIterator> 258*0eae32dcSDimitry Andric requires default_initializable<iter_value_t<ForwardIterator>> 259*0eae32dcSDimitry Andric ForwardIterator ranges::uninitialized_default_construct_n(ForwardIterator first, iter_difference_t<ForwardIterator> n); // since C++20 260*0eae32dcSDimitry Andric 2610b57cec5SDimitry Andrictemplate <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andrictemplate<class X> 2640b57cec5SDimitry Andricclass auto_ptr // deprecated in C++11, removed in C++17 2650b57cec5SDimitry Andric{ 2660b57cec5SDimitry Andricpublic: 2670b57cec5SDimitry Andric typedef X element_type; 2680b57cec5SDimitry Andric 2690b57cec5SDimitry Andric explicit auto_ptr(X* p =0) throw(); 2700b57cec5SDimitry Andric auto_ptr(auto_ptr&) throw(); 2710b57cec5SDimitry Andric template<class Y> auto_ptr(auto_ptr<Y>&) throw(); 2720b57cec5SDimitry Andric auto_ptr& operator=(auto_ptr&) throw(); 2730b57cec5SDimitry Andric template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw(); 2740b57cec5SDimitry Andric auto_ptr& operator=(auto_ptr_ref<X> r) throw(); 2750b57cec5SDimitry Andric ~auto_ptr() throw(); 2760b57cec5SDimitry Andric 2770b57cec5SDimitry Andric typename add_lvalue_reference<X>::type operator*() const throw(); 2780b57cec5SDimitry Andric X* operator->() const throw(); 2790b57cec5SDimitry Andric X* get() const throw(); 2800b57cec5SDimitry Andric X* release() throw(); 2810b57cec5SDimitry Andric void reset(X* p =0) throw(); 2820b57cec5SDimitry Andric 2830b57cec5SDimitry Andric auto_ptr(auto_ptr_ref<X>) throw(); 2840b57cec5SDimitry Andric template<class Y> operator auto_ptr_ref<Y>() throw(); 2850b57cec5SDimitry Andric template<class Y> operator auto_ptr<Y>() throw(); 2860b57cec5SDimitry Andric}; 2870b57cec5SDimitry Andric 2880b57cec5SDimitry Andrictemplate <class T> 2890b57cec5SDimitry Andricstruct default_delete 2900b57cec5SDimitry Andric{ 2910b57cec5SDimitry Andric constexpr default_delete() noexcept = default; 2920b57cec5SDimitry Andric template <class U> default_delete(const default_delete<U>&) noexcept; 2930b57cec5SDimitry Andric 2940b57cec5SDimitry Andric void operator()(T*) const noexcept; 2950b57cec5SDimitry Andric}; 2960b57cec5SDimitry Andric 2970b57cec5SDimitry Andrictemplate <class T> 2980b57cec5SDimitry Andricstruct default_delete<T[]> 2990b57cec5SDimitry Andric{ 3000b57cec5SDimitry Andric constexpr default_delete() noexcept = default; 3010b57cec5SDimitry Andric void operator()(T*) const noexcept; 3020b57cec5SDimitry Andric template <class U> void operator()(U*) const = delete; 3030b57cec5SDimitry Andric}; 3040b57cec5SDimitry Andric 3050b57cec5SDimitry Andrictemplate <class T, class D = default_delete<T>> 3060b57cec5SDimitry Andricclass unique_ptr 3070b57cec5SDimitry Andric{ 3080b57cec5SDimitry Andricpublic: 3090b57cec5SDimitry Andric typedef see below pointer; 3100b57cec5SDimitry Andric typedef T element_type; 3110b57cec5SDimitry Andric typedef D deleter_type; 3120b57cec5SDimitry Andric 3130b57cec5SDimitry Andric // constructors 3140b57cec5SDimitry Andric constexpr unique_ptr() noexcept; 3150b57cec5SDimitry Andric explicit unique_ptr(pointer p) noexcept; 3160b57cec5SDimitry Andric unique_ptr(pointer p, see below d1) noexcept; 3170b57cec5SDimitry Andric unique_ptr(pointer p, see below d2) noexcept; 3180b57cec5SDimitry Andric unique_ptr(unique_ptr&& u) noexcept; 3190b57cec5SDimitry Andric unique_ptr(nullptr_t) noexcept : unique_ptr() { } 3200b57cec5SDimitry Andric template <class U, class E> 3210b57cec5SDimitry Andric unique_ptr(unique_ptr<U, E>&& u) noexcept; 3220b57cec5SDimitry Andric template <class U> 3230b57cec5SDimitry Andric unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17 3240b57cec5SDimitry Andric 3250b57cec5SDimitry Andric // destructor 3260b57cec5SDimitry Andric ~unique_ptr(); 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric // assignment 3290b57cec5SDimitry Andric unique_ptr& operator=(unique_ptr&& u) noexcept; 3300b57cec5SDimitry Andric template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept; 3310b57cec5SDimitry Andric unique_ptr& operator=(nullptr_t) noexcept; 3320b57cec5SDimitry Andric 3330b57cec5SDimitry Andric // observers 3340b57cec5SDimitry Andric typename add_lvalue_reference<T>::type operator*() const; 3350b57cec5SDimitry Andric pointer operator->() const noexcept; 3360b57cec5SDimitry Andric pointer get() const noexcept; 3370b57cec5SDimitry Andric deleter_type& get_deleter() noexcept; 3380b57cec5SDimitry Andric const deleter_type& get_deleter() const noexcept; 3390b57cec5SDimitry Andric explicit operator bool() const noexcept; 3400b57cec5SDimitry Andric 3410b57cec5SDimitry Andric // modifiers 3420b57cec5SDimitry Andric pointer release() noexcept; 3430b57cec5SDimitry Andric void reset(pointer p = pointer()) noexcept; 3440b57cec5SDimitry Andric void swap(unique_ptr& u) noexcept; 3450b57cec5SDimitry Andric}; 3460b57cec5SDimitry Andric 3470b57cec5SDimitry Andrictemplate <class T, class D> 3480b57cec5SDimitry Andricclass unique_ptr<T[], D> 3490b57cec5SDimitry Andric{ 3500b57cec5SDimitry Andricpublic: 3510b57cec5SDimitry Andric typedef implementation-defined pointer; 3520b57cec5SDimitry Andric typedef T element_type; 3530b57cec5SDimitry Andric typedef D deleter_type; 3540b57cec5SDimitry Andric 3550b57cec5SDimitry Andric // constructors 3560b57cec5SDimitry Andric constexpr unique_ptr() noexcept; 3570b57cec5SDimitry Andric explicit unique_ptr(pointer p) noexcept; 3580b57cec5SDimitry Andric unique_ptr(pointer p, see below d) noexcept; 3590b57cec5SDimitry Andric unique_ptr(pointer p, see below d) noexcept; 3600b57cec5SDimitry Andric unique_ptr(unique_ptr&& u) noexcept; 3610b57cec5SDimitry Andric unique_ptr(nullptr_t) noexcept : unique_ptr() { } 3620b57cec5SDimitry Andric 3630b57cec5SDimitry Andric // destructor 3640b57cec5SDimitry Andric ~unique_ptr(); 3650b57cec5SDimitry Andric 3660b57cec5SDimitry Andric // assignment 3670b57cec5SDimitry Andric unique_ptr& operator=(unique_ptr&& u) noexcept; 3680b57cec5SDimitry Andric unique_ptr& operator=(nullptr_t) noexcept; 3690b57cec5SDimitry Andric 3700b57cec5SDimitry Andric // observers 3710b57cec5SDimitry Andric T& operator[](size_t i) const; 3720b57cec5SDimitry Andric pointer get() const noexcept; 3730b57cec5SDimitry Andric deleter_type& get_deleter() noexcept; 3740b57cec5SDimitry Andric const deleter_type& get_deleter() const noexcept; 3750b57cec5SDimitry Andric explicit operator bool() const noexcept; 3760b57cec5SDimitry Andric 3770b57cec5SDimitry Andric // modifiers 3780b57cec5SDimitry Andric pointer release() noexcept; 3790b57cec5SDimitry Andric void reset(pointer p = pointer()) noexcept; 3800b57cec5SDimitry Andric void reset(nullptr_t) noexcept; 3810b57cec5SDimitry Andric template <class U> void reset(U) = delete; 3820b57cec5SDimitry Andric void swap(unique_ptr& u) noexcept; 3830b57cec5SDimitry Andric}; 3840b57cec5SDimitry Andric 3850b57cec5SDimitry Andrictemplate <class T, class D> 3860b57cec5SDimitry Andric void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; 3870b57cec5SDimitry Andric 3880b57cec5SDimitry Andrictemplate <class T1, class D1, class T2, class D2> 3890b57cec5SDimitry Andric bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 3900b57cec5SDimitry Andrictemplate <class T1, class D1, class T2, class D2> 3910b57cec5SDimitry Andric bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 3920b57cec5SDimitry Andrictemplate <class T1, class D1, class T2, class D2> 3930b57cec5SDimitry Andric bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 3940b57cec5SDimitry Andrictemplate <class T1, class D1, class T2, class D2> 3950b57cec5SDimitry Andric bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 3960b57cec5SDimitry Andrictemplate <class T1, class D1, class T2, class D2> 3970b57cec5SDimitry Andric bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 3980b57cec5SDimitry Andrictemplate <class T1, class D1, class T2, class D2> 3990b57cec5SDimitry Andric bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); 4000b57cec5SDimitry Andric 4010b57cec5SDimitry Andrictemplate <class T, class D> 4020b57cec5SDimitry Andric bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; 4030b57cec5SDimitry Andrictemplate <class T, class D> 4040b57cec5SDimitry Andric bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept; 4050b57cec5SDimitry Andrictemplate <class T, class D> 4060b57cec5SDimitry Andric bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept; 4070b57cec5SDimitry Andrictemplate <class T, class D> 4080b57cec5SDimitry Andric bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept; 4090b57cec5SDimitry Andric 4100b57cec5SDimitry Andrictemplate <class T, class D> 4110b57cec5SDimitry Andric bool operator<(const unique_ptr<T, D>& x, nullptr_t); 4120b57cec5SDimitry Andrictemplate <class T, class D> 4130b57cec5SDimitry Andric bool operator<(nullptr_t, const unique_ptr<T, D>& y); 4140b57cec5SDimitry Andrictemplate <class T, class D> 4150b57cec5SDimitry Andric bool operator<=(const unique_ptr<T, D>& x, nullptr_t); 4160b57cec5SDimitry Andrictemplate <class T, class D> 4170b57cec5SDimitry Andric bool operator<=(nullptr_t, const unique_ptr<T, D>& y); 4180b57cec5SDimitry Andrictemplate <class T, class D> 4190b57cec5SDimitry Andric bool operator>(const unique_ptr<T, D>& x, nullptr_t); 4200b57cec5SDimitry Andrictemplate <class T, class D> 4210b57cec5SDimitry Andric bool operator>(nullptr_t, const unique_ptr<T, D>& y); 4220b57cec5SDimitry Andrictemplate <class T, class D> 4230b57cec5SDimitry Andric bool operator>=(const unique_ptr<T, D>& x, nullptr_t); 4240b57cec5SDimitry Andrictemplate <class T, class D> 4250b57cec5SDimitry Andric bool operator>=(nullptr_t, const unique_ptr<T, D>& y); 4260b57cec5SDimitry Andric 4270b57cec5SDimitry Andricclass bad_weak_ptr 4280b57cec5SDimitry Andric : public std::exception 4290b57cec5SDimitry Andric{ 4300b57cec5SDimitry Andric bad_weak_ptr() noexcept; 4310b57cec5SDimitry Andric}; 4320b57cec5SDimitry Andric 4330b57cec5SDimitry Andrictemplate<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14 4340b57cec5SDimitry Andrictemplate<class T> unique_ptr<T> make_unique(size_t n); // C++14 4350b57cec5SDimitry Andrictemplate<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N] 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andrictemplate<class E, class T, class Y, class D> 4380b57cec5SDimitry Andric basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p); 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andrictemplate<class T> 4410b57cec5SDimitry Andricclass shared_ptr 4420b57cec5SDimitry Andric{ 4430b57cec5SDimitry Andricpublic: 444349cc55cSDimitry Andric typedef T element_type; // until C++17 445349cc55cSDimitry Andric typedef remove_extent_t<T> element_type; // since C++17 4460b57cec5SDimitry Andric typedef weak_ptr<T> weak_type; // C++17 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andric // constructors: 4490b57cec5SDimitry Andric constexpr shared_ptr() noexcept; 4500b57cec5SDimitry Andric template<class Y> explicit shared_ptr(Y* p); 4510b57cec5SDimitry Andric template<class Y, class D> shared_ptr(Y* p, D d); 4520b57cec5SDimitry Andric template<class Y, class D, class A> shared_ptr(Y* p, D d, A a); 4530b57cec5SDimitry Andric template <class D> shared_ptr(nullptr_t p, D d); 4540b57cec5SDimitry Andric template <class D, class A> shared_ptr(nullptr_t p, D d, A a); 4550b57cec5SDimitry Andric template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept; 4560b57cec5SDimitry Andric shared_ptr(const shared_ptr& r) noexcept; 4570b57cec5SDimitry Andric template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept; 4580b57cec5SDimitry Andric shared_ptr(shared_ptr&& r) noexcept; 4590b57cec5SDimitry Andric template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept; 4600b57cec5SDimitry Andric template<class Y> explicit shared_ptr(const weak_ptr<Y>& r); 4610b57cec5SDimitry Andric template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17 4620b57cec5SDimitry Andric template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r); 4630b57cec5SDimitry Andric shared_ptr(nullptr_t) : shared_ptr() { } 4640b57cec5SDimitry Andric 4650b57cec5SDimitry Andric // destructor: 4660b57cec5SDimitry Andric ~shared_ptr(); 4670b57cec5SDimitry Andric 4680b57cec5SDimitry Andric // assignment: 4690b57cec5SDimitry Andric shared_ptr& operator=(const shared_ptr& r) noexcept; 4700b57cec5SDimitry Andric template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept; 4710b57cec5SDimitry Andric shared_ptr& operator=(shared_ptr&& r) noexcept; 4720b57cec5SDimitry Andric template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r); 4730b57cec5SDimitry Andric template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17 4740b57cec5SDimitry Andric template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r); 4750b57cec5SDimitry Andric 4760b57cec5SDimitry Andric // modifiers: 4770b57cec5SDimitry Andric void swap(shared_ptr& r) noexcept; 4780b57cec5SDimitry Andric void reset() noexcept; 4790b57cec5SDimitry Andric template<class Y> void reset(Y* p); 4800b57cec5SDimitry Andric template<class Y, class D> void reset(Y* p, D d); 4810b57cec5SDimitry Andric template<class Y, class D, class A> void reset(Y* p, D d, A a); 4820b57cec5SDimitry Andric 4830b57cec5SDimitry Andric // observers: 4840b57cec5SDimitry Andric T* get() const noexcept; 4850b57cec5SDimitry Andric T& operator*() const noexcept; 4860b57cec5SDimitry Andric T* operator->() const noexcept; 4870b57cec5SDimitry Andric long use_count() const noexcept; 4880b57cec5SDimitry Andric bool unique() const noexcept; 4890b57cec5SDimitry Andric explicit operator bool() const noexcept; 4900b57cec5SDimitry Andric template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; 4910b57cec5SDimitry Andric template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; 4920b57cec5SDimitry Andric}; 4930b57cec5SDimitry Andric 4945ffd83dbSDimitry Andrictemplate<class T> 4955ffd83dbSDimitry Andricshared_ptr(weak_ptr<T>) -> shared_ptr<T>; 4965ffd83dbSDimitry Andrictemplate<class T, class D> 4975ffd83dbSDimitry Andricshared_ptr(unique_ptr<T, D>) -> shared_ptr<T>; 4985ffd83dbSDimitry Andric 4990b57cec5SDimitry Andric// shared_ptr comparisons: 5000b57cec5SDimitry Andrictemplate<class T, class U> 5010b57cec5SDimitry Andric bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 5020b57cec5SDimitry Andrictemplate<class T, class U> 5030b57cec5SDimitry Andric bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 5040b57cec5SDimitry Andrictemplate<class T, class U> 5050b57cec5SDimitry Andric bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 5060b57cec5SDimitry Andrictemplate<class T, class U> 5070b57cec5SDimitry Andric bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 5080b57cec5SDimitry Andrictemplate<class T, class U> 5090b57cec5SDimitry Andric bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 5100b57cec5SDimitry Andrictemplate<class T, class U> 5110b57cec5SDimitry Andric bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept; 5120b57cec5SDimitry Andric 5130b57cec5SDimitry Andrictemplate <class T> 5140b57cec5SDimitry Andric bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept; 5150b57cec5SDimitry Andrictemplate <class T> 5160b57cec5SDimitry Andric bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept; 5170b57cec5SDimitry Andrictemplate <class T> 5180b57cec5SDimitry Andric bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept; 5190b57cec5SDimitry Andrictemplate <class T> 5200b57cec5SDimitry Andric bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept; 5210b57cec5SDimitry Andrictemplate <class T> 5220b57cec5SDimitry Andric bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept; 5230b57cec5SDimitry Andrictemplate <class T> 5240b57cec5SDimitry Andricbool operator<(nullptr_t, const shared_ptr<T>& y) noexcept; 5250b57cec5SDimitry Andrictemplate <class T> 5260b57cec5SDimitry Andric bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept; 5270b57cec5SDimitry Andrictemplate <class T> 5280b57cec5SDimitry Andric bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept; 5290b57cec5SDimitry Andrictemplate <class T> 5300b57cec5SDimitry Andric bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept; 5310b57cec5SDimitry Andrictemplate <class T> 5320b57cec5SDimitry Andric bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept; 5330b57cec5SDimitry Andrictemplate <class T> 5340b57cec5SDimitry Andric bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept; 5350b57cec5SDimitry Andrictemplate <class T> 5360b57cec5SDimitry Andric bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept; 5370b57cec5SDimitry Andric 5380b57cec5SDimitry Andric// shared_ptr specialized algorithms: 5390b57cec5SDimitry Andrictemplate<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept; 5400b57cec5SDimitry Andric 5410b57cec5SDimitry Andric// shared_ptr casts: 5420b57cec5SDimitry Andrictemplate<class T, class U> 5430b57cec5SDimitry Andric shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept; 5440b57cec5SDimitry Andrictemplate<class T, class U> 5450b57cec5SDimitry Andric shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept; 5460b57cec5SDimitry Andrictemplate<class T, class U> 5470b57cec5SDimitry Andric shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept; 5480b57cec5SDimitry Andric 5490b57cec5SDimitry Andric// shared_ptr I/O: 5500b57cec5SDimitry Andrictemplate<class E, class T, class Y> 5510b57cec5SDimitry Andric basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p); 5520b57cec5SDimitry Andric 5530b57cec5SDimitry Andric// shared_ptr get_deleter: 5540b57cec5SDimitry Andrictemplate<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept; 5550b57cec5SDimitry Andric 5560b57cec5SDimitry Andrictemplate<class T, class... Args> 5570b57cec5SDimitry Andric shared_ptr<T> make_shared(Args&&... args); 5580b57cec5SDimitry Andrictemplate<class T, class A, class... Args> 5590b57cec5SDimitry Andric shared_ptr<T> allocate_shared(const A& a, Args&&... args); 5600b57cec5SDimitry Andric 5610b57cec5SDimitry Andrictemplate<class T> 5620b57cec5SDimitry Andricclass weak_ptr 5630b57cec5SDimitry Andric{ 5640b57cec5SDimitry Andricpublic: 565349cc55cSDimitry Andric typedef T element_type; // until C++17 566349cc55cSDimitry Andric typedef remove_extent_t<T> element_type; // since C++17 5670b57cec5SDimitry Andric 5680b57cec5SDimitry Andric // constructors 5690b57cec5SDimitry Andric constexpr weak_ptr() noexcept; 5700b57cec5SDimitry Andric template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept; 5710b57cec5SDimitry Andric weak_ptr(weak_ptr const& r) noexcept; 5720b57cec5SDimitry Andric template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept; 5730b57cec5SDimitry Andric weak_ptr(weak_ptr&& r) noexcept; // C++14 5740b57cec5SDimitry Andric template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14 5750b57cec5SDimitry Andric 5760b57cec5SDimitry Andric // destructor 5770b57cec5SDimitry Andric ~weak_ptr(); 5780b57cec5SDimitry Andric 5790b57cec5SDimitry Andric // assignment 5800b57cec5SDimitry Andric weak_ptr& operator=(weak_ptr const& r) noexcept; 5810b57cec5SDimitry Andric template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept; 5820b57cec5SDimitry Andric template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept; 5830b57cec5SDimitry Andric weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14 5840b57cec5SDimitry Andric template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14 5850b57cec5SDimitry Andric 5860b57cec5SDimitry Andric // modifiers 5870b57cec5SDimitry Andric void swap(weak_ptr& r) noexcept; 5880b57cec5SDimitry Andric void reset() noexcept; 5890b57cec5SDimitry Andric 5900b57cec5SDimitry Andric // observers 5910b57cec5SDimitry Andric long use_count() const noexcept; 5920b57cec5SDimitry Andric bool expired() const noexcept; 5930b57cec5SDimitry Andric shared_ptr<T> lock() const noexcept; 5940b57cec5SDimitry Andric template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept; 5950b57cec5SDimitry Andric template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept; 5960b57cec5SDimitry Andric}; 5970b57cec5SDimitry Andric 5985ffd83dbSDimitry Andrictemplate<class T> 5995ffd83dbSDimitry Andricweak_ptr(shared_ptr<T>) -> weak_ptr<T>; 6005ffd83dbSDimitry Andric 6010b57cec5SDimitry Andric// weak_ptr specialized algorithms: 6020b57cec5SDimitry Andrictemplate<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept; 6030b57cec5SDimitry Andric 6040b57cec5SDimitry Andric// class owner_less: 6050b57cec5SDimitry Andrictemplate<class T> struct owner_less; 6060b57cec5SDimitry Andric 6070b57cec5SDimitry Andrictemplate<class T> 6080b57cec5SDimitry Andricstruct owner_less<shared_ptr<T> > 6090b57cec5SDimitry Andric : binary_function<shared_ptr<T>, shared_ptr<T>, bool> 6100b57cec5SDimitry Andric{ 6110b57cec5SDimitry Andric typedef bool result_type; 6120b57cec5SDimitry Andric bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept; 6130b57cec5SDimitry Andric bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; 6140b57cec5SDimitry Andric bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; 6150b57cec5SDimitry Andric}; 6160b57cec5SDimitry Andric 6170b57cec5SDimitry Andrictemplate<class T> 6180b57cec5SDimitry Andricstruct owner_less<weak_ptr<T> > 6190b57cec5SDimitry Andric : binary_function<weak_ptr<T>, weak_ptr<T>, bool> 6200b57cec5SDimitry Andric{ 6210b57cec5SDimitry Andric typedef bool result_type; 6220b57cec5SDimitry Andric bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept; 6230b57cec5SDimitry Andric bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept; 6240b57cec5SDimitry Andric bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept; 6250b57cec5SDimitry Andric}; 6260b57cec5SDimitry Andric 6270b57cec5SDimitry Andrictemplate <> // Added in C++14 6280b57cec5SDimitry Andricstruct owner_less<void> 6290b57cec5SDimitry Andric{ 6300b57cec5SDimitry Andric template <class _Tp, class _Up> 6310b57cec5SDimitry Andric bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; 6320b57cec5SDimitry Andric template <class _Tp, class _Up> 6330b57cec5SDimitry Andric bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; 6340b57cec5SDimitry Andric template <class _Tp, class _Up> 6350b57cec5SDimitry Andric bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept; 6360b57cec5SDimitry Andric template <class _Tp, class _Up> 6370b57cec5SDimitry Andric bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept; 6380b57cec5SDimitry Andric 6390b57cec5SDimitry Andric typedef void is_transparent; 6400b57cec5SDimitry Andric}; 6410b57cec5SDimitry Andric 6420b57cec5SDimitry Andrictemplate<class T> 6430b57cec5SDimitry Andricclass enable_shared_from_this 6440b57cec5SDimitry Andric{ 6450b57cec5SDimitry Andricprotected: 6460b57cec5SDimitry Andric constexpr enable_shared_from_this() noexcept; 6470b57cec5SDimitry Andric enable_shared_from_this(enable_shared_from_this const&) noexcept; 6480b57cec5SDimitry Andric enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; 6490b57cec5SDimitry Andric ~enable_shared_from_this(); 6500b57cec5SDimitry Andricpublic: 6510b57cec5SDimitry Andric shared_ptr<T> shared_from_this(); 6520b57cec5SDimitry Andric shared_ptr<T const> shared_from_this() const; 6530b57cec5SDimitry Andric}; 6540b57cec5SDimitry Andric 6550b57cec5SDimitry Andrictemplate<class T> 6560b57cec5SDimitry Andric bool atomic_is_lock_free(const shared_ptr<T>* p); 6570b57cec5SDimitry Andrictemplate<class T> 6580b57cec5SDimitry Andric shared_ptr<T> atomic_load(const shared_ptr<T>* p); 6590b57cec5SDimitry Andrictemplate<class T> 6600b57cec5SDimitry Andric shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo); 6610b57cec5SDimitry Andrictemplate<class T> 6620b57cec5SDimitry Andric void atomic_store(shared_ptr<T>* p, shared_ptr<T> r); 6630b57cec5SDimitry Andrictemplate<class T> 6640b57cec5SDimitry Andric void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 6650b57cec5SDimitry Andrictemplate<class T> 6660b57cec5SDimitry Andric shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r); 6670b57cec5SDimitry Andrictemplate<class T> 6680b57cec5SDimitry Andric shared_ptr<T> 6690b57cec5SDimitry Andric atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo); 6700b57cec5SDimitry Andrictemplate<class T> 6710b57cec5SDimitry Andric bool 6720b57cec5SDimitry Andric atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 6730b57cec5SDimitry Andrictemplate<class T> 6740b57cec5SDimitry Andric bool 6750b57cec5SDimitry Andric atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w); 6760b57cec5SDimitry Andrictemplate<class T> 6770b57cec5SDimitry Andric bool 6780b57cec5SDimitry Andric atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 6790b57cec5SDimitry Andric shared_ptr<T> w, memory_order success, 6800b57cec5SDimitry Andric memory_order failure); 6810b57cec5SDimitry Andrictemplate<class T> 6820b57cec5SDimitry Andric bool 6830b57cec5SDimitry Andric atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v, 6840b57cec5SDimitry Andric shared_ptr<T> w, memory_order success, 6850b57cec5SDimitry Andric memory_order failure); 6860b57cec5SDimitry Andric// Hash support 6870b57cec5SDimitry Andrictemplate <class T> struct hash; 6880b57cec5SDimitry Andrictemplate <class T, class D> struct hash<unique_ptr<T, D> >; 6890b57cec5SDimitry Andrictemplate <class T> struct hash<shared_ptr<T> >; 6900b57cec5SDimitry Andric 6910b57cec5SDimitry Andrictemplate <class T, class Alloc> 6920b57cec5SDimitry Andric inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; 6930b57cec5SDimitry Andric 6940b57cec5SDimitry Andricvoid* align(size_t alignment, size_t size, void*& ptr, size_t& space); 6950b57cec5SDimitry Andric 6960b57cec5SDimitry Andric} // std 6970b57cec5SDimitry Andric 6980b57cec5SDimitry Andric*/ 6990b57cec5SDimitry Andric 7000b57cec5SDimitry Andric#include <__config> 701fe6060f1SDimitry Andric#include <__functional_base> 702fe6060f1SDimitry Andric#include <__memory/addressof.h> 703fe6060f1SDimitry Andric#include <__memory/allocation_guard.h> 704fe6060f1SDimitry Andric#include <__memory/allocator.h> 705fe6060f1SDimitry Andric#include <__memory/allocator_arg_t.h> 706fe6060f1SDimitry Andric#include <__memory/allocator_traits.h> 707fe6060f1SDimitry Andric#include <__memory/compressed_pair.h> 708*0eae32dcSDimitry Andric#include <__memory/concepts.h> 709fe6060f1SDimitry Andric#include <__memory/construct_at.h> 710fe6060f1SDimitry Andric#include <__memory/pointer_traits.h> 711*0eae32dcSDimitry Andric#include <__memory/ranges_uninitialized_algorithms.h> 712fe6060f1SDimitry Andric#include <__memory/raw_storage_iterator.h> 713fe6060f1SDimitry Andric#include <__memory/shared_ptr.h> 714fe6060f1SDimitry Andric#include <__memory/temporary_buffer.h> 715fe6060f1SDimitry Andric#include <__memory/uninitialized_algorithms.h> 716fe6060f1SDimitry Andric#include <__memory/unique_ptr.h> 717fe6060f1SDimitry Andric#include <__memory/uses_allocator.h> 718fe6060f1SDimitry Andric#include <compare> 7190b57cec5SDimitry Andric#include <cstddef> 7200b57cec5SDimitry Andric#include <cstdint> 7210b57cec5SDimitry Andric#include <cstring> 722fe6060f1SDimitry Andric#include <iosfwd> 723fe6060f1SDimitry Andric#include <iterator> 724fe6060f1SDimitry Andric#include <new> 725fe6060f1SDimitry Andric#include <stdexcept> 726fe6060f1SDimitry Andric#include <tuple> 727fe6060f1SDimitry Andric#include <type_traits> 728fe6060f1SDimitry Andric#include <typeinfo> 729fe6060f1SDimitry Andric#include <utility> 7300b57cec5SDimitry Andric#include <version> 7310b57cec5SDimitry Andric 732fe6060f1SDimitry Andric#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR) 733fe6060f1SDimitry Andric# include <__memory/auto_ptr.h> 734fe6060f1SDimitry Andric#endif 735fe6060f1SDimitry Andric 7360b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 7370b57cec5SDimitry Andric#pragma GCC system_header 7380b57cec5SDimitry Andric#endif 7390b57cec5SDimitry Andric 7400b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD 7410b57cec5SDimitry Andric 7420b57cec5SDimitry Andrictemplate <class _Alloc, class _Ptr> 7430b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 744e8d8bef9SDimitry Andricvoid __construct_forward_with_exception_guarantees(_Alloc& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2) { 745e8d8bef9SDimitry Andric static_assert(__is_cpp17_move_insertable<_Alloc>::value, 746e8d8bef9SDimitry Andric "The specified type does not meet the requirements of Cpp17MoveInsertable"); 747e8d8bef9SDimitry Andric typedef allocator_traits<_Alloc> _Traits; 748e8d8bef9SDimitry Andric for (; __begin1 != __end1; ++__begin1, (void)++__begin2) { 749e8d8bef9SDimitry Andric _Traits::construct(__a, _VSTD::__to_address(__begin2), 750e40139ffSDimitry Andric#ifdef _LIBCPP_NO_EXCEPTIONS 751e40139ffSDimitry Andric _VSTD::move(*__begin1) 752e40139ffSDimitry Andric#else 753e40139ffSDimitry Andric _VSTD::move_if_noexcept(*__begin1) 754e40139ffSDimitry Andric#endif 755e40139ffSDimitry Andric ); 7560b57cec5SDimitry Andric } 757e8d8bef9SDimitry Andric} 7580b57cec5SDimitry Andric 759e8d8bef9SDimitry Andrictemplate <class _Alloc, class _Tp, typename enable_if< 760e8d8bef9SDimitry Andric (__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Tp*, _Tp>::value) && 761e8d8bef9SDimitry Andric is_trivially_move_constructible<_Tp>::value 762e8d8bef9SDimitry Andric>::type> 7630b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 764e8d8bef9SDimitry Andricvoid __construct_forward_with_exception_guarantees(_Alloc&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2) { 7650b57cec5SDimitry Andric ptrdiff_t _Np = __end1 - __begin1; 766e8d8bef9SDimitry Andric if (_Np > 0) { 7670b57cec5SDimitry Andric _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp)); 7680b57cec5SDimitry Andric __begin2 += _Np; 7690b57cec5SDimitry Andric } 7700b57cec5SDimitry Andric} 7710b57cec5SDimitry Andric 772e8d8bef9SDimitry Andrictemplate <class _Alloc, class _Iter, class _Ptr> 7730b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 774e8d8bef9SDimitry Andricvoid __construct_range_forward(_Alloc& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2) { 775e8d8bef9SDimitry Andric typedef allocator_traits<_Alloc> _Traits; 776e8d8bef9SDimitry Andric for (; __begin1 != __end1; ++__begin1, (void) ++__begin2) { 777e8d8bef9SDimitry Andric _Traits::construct(__a, _VSTD::__to_address(__begin2), *__begin1); 778e8d8bef9SDimitry Andric } 7790b57cec5SDimitry Andric} 7800b57cec5SDimitry Andric 781e8d8bef9SDimitry Andrictemplate <class _Alloc, class _Source, class _Dest, 782e8d8bef9SDimitry Andric class _RawSource = typename remove_const<_Source>::type, 783e8d8bef9SDimitry Andric class _RawDest = typename remove_const<_Dest>::type, 784e8d8bef9SDimitry Andric class = 785e8d8bef9SDimitry Andric typename enable_if< 786e8d8bef9SDimitry Andric is_trivially_copy_constructible<_Dest>::value && 787e8d8bef9SDimitry Andric is_same<_RawSource, _RawDest>::value && 788e8d8bef9SDimitry Andric (__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Dest*, _Source&>::value) 789e8d8bef9SDimitry Andric >::type> 7900b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 791e8d8bef9SDimitry Andricvoid __construct_range_forward(_Alloc&, _Source* __begin1, _Source* __end1, _Dest*& __begin2) { 7920b57cec5SDimitry Andric ptrdiff_t _Np = __end1 - __begin1; 793e8d8bef9SDimitry Andric if (_Np > 0) { 794e8d8bef9SDimitry Andric _VSTD::memcpy(const_cast<_RawDest*>(__begin2), __begin1, _Np * sizeof(_Dest)); 7950b57cec5SDimitry Andric __begin2 += _Np; 7960b57cec5SDimitry Andric } 7970b57cec5SDimitry Andric} 7980b57cec5SDimitry Andric 799e8d8bef9SDimitry Andrictemplate <class _Alloc, class _Ptr> 8000b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 801e8d8bef9SDimitry Andricvoid __construct_backward_with_exception_guarantees(_Alloc& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2) { 802e8d8bef9SDimitry Andric static_assert(__is_cpp17_move_insertable<_Alloc>::value, 803e40139ffSDimitry Andric "The specified type does not meet the requirements of Cpp17MoveInsertable"); 804e8d8bef9SDimitry Andric typedef allocator_traits<_Alloc> _Traits; 805e8d8bef9SDimitry Andric while (__end1 != __begin1) { 806e8d8bef9SDimitry Andric _Traits::construct(__a, _VSTD::__to_address(__end2 - 1), 807e40139ffSDimitry Andric#ifdef _LIBCPP_NO_EXCEPTIONS 808e40139ffSDimitry Andric _VSTD::move(*--__end1) 809e40139ffSDimitry Andric#else 810e40139ffSDimitry Andric _VSTD::move_if_noexcept(*--__end1) 811e40139ffSDimitry Andric#endif 812e40139ffSDimitry Andric ); 8130b57cec5SDimitry Andric --__end2; 8140b57cec5SDimitry Andric } 8150b57cec5SDimitry Andric} 8160b57cec5SDimitry Andric 817e8d8bef9SDimitry Andrictemplate <class _Alloc, class _Tp, class = typename enable_if< 818e8d8bef9SDimitry Andric (__is_default_allocator<_Alloc>::value || !__has_construct<_Alloc, _Tp*, _Tp>::value) && 819e8d8bef9SDimitry Andric is_trivially_move_constructible<_Tp>::value 820e8d8bef9SDimitry Andric>::type> 8210b57cec5SDimitry Andric_LIBCPP_INLINE_VISIBILITY 822e8d8bef9SDimitry Andricvoid __construct_backward_with_exception_guarantees(_Alloc&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2) { 8230b57cec5SDimitry Andric ptrdiff_t _Np = __end1 - __begin1; 8240b57cec5SDimitry Andric __end2 -= _Np; 8250b57cec5SDimitry Andric if (_Np > 0) 826fe6060f1SDimitry Andric _VSTD::memcpy(static_cast<void*>(__end2), static_cast<void const*>(__begin1), _Np * sizeof(_Tp)); 8270b57cec5SDimitry Andric} 8280b57cec5SDimitry Andric 8290b57cec5SDimitry Andricstruct __destruct_n 8300b57cec5SDimitry Andric{ 8310b57cec5SDimitry Andricprivate: 8320b57cec5SDimitry Andric size_t __size_; 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andric template <class _Tp> 8350b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT 8360b57cec5SDimitry Andric {for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();} 8370b57cec5SDimitry Andric 8380b57cec5SDimitry Andric template <class _Tp> 8390b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT 8400b57cec5SDimitry Andric {} 8410b57cec5SDimitry Andric 8420b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT 8430b57cec5SDimitry Andric {++__size_;} 8440b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT 8450b57cec5SDimitry Andric {} 8460b57cec5SDimitry Andric 8470b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT 8480b57cec5SDimitry Andric {__size_ = __s;} 8490b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT 8500b57cec5SDimitry Andric {} 8510b57cec5SDimitry Andricpublic: 8520b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT 8530b57cec5SDimitry Andric : __size_(__s) {} 8540b57cec5SDimitry Andric 8550b57cec5SDimitry Andric template <class _Tp> 856e8d8bef9SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __incr() _NOEXCEPT 8570b57cec5SDimitry Andric {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 8580b57cec5SDimitry Andric 8590b57cec5SDimitry Andric template <class _Tp> 8600b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT 8610b57cec5SDimitry Andric {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 8620b57cec5SDimitry Andric 8630b57cec5SDimitry Andric template <class _Tp> 8640b57cec5SDimitry Andric _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT 8650b57cec5SDimitry Andric {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());} 8660b57cec5SDimitry Andric}; 8670b57cec5SDimitry Andric 8680b57cec5SDimitry Andric_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space); 8690b57cec5SDimitry Andric 8700b57cec5SDimitry Andric// --- Helper for container swap -- 8710b57cec5SDimitry Andrictemplate <typename _Alloc> 872*0eae32dcSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 8730b57cec5SDimitry Andricvoid __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type) 874*0eae32dcSDimitry Andric#if _LIBCPP_STD_VER > 11 8750b57cec5SDimitry Andric _NOEXCEPT 8760b57cec5SDimitry Andric#else 8770b57cec5SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 8780b57cec5SDimitry Andric#endif 8790b57cec5SDimitry Andric{ 8800b57cec5SDimitry Andric using _VSTD::swap; 8810b57cec5SDimitry Andric swap(__a1, __a2); 8820b57cec5SDimitry Andric} 8830b57cec5SDimitry Andric 8840b57cec5SDimitry Andrictemplate <typename _Alloc> 885*0eae32dcSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 8860b57cec5SDimitry Andricvoid __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {} 8870b57cec5SDimitry Andric 888e8d8bef9SDimitry Andrictemplate <typename _Alloc> 889*0eae32dcSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX11 890e8d8bef9SDimitry Andricvoid __swap_allocator(_Alloc & __a1, _Alloc & __a2) 891*0eae32dcSDimitry Andric#if _LIBCPP_STD_VER > 11 892e8d8bef9SDimitry Andric _NOEXCEPT 893e8d8bef9SDimitry Andric#else 894e8d8bef9SDimitry Andric _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value) 895e8d8bef9SDimitry Andric#endif 896e8d8bef9SDimitry Andric{ 897e8d8bef9SDimitry Andric _VSTD::__swap_allocator(__a1, __a2, 898fe6060f1SDimitry Andric integral_constant<bool, allocator_traits<_Alloc>::propagate_on_container_swap::value>()); 899e8d8bef9SDimitry Andric} 900e8d8bef9SDimitry Andric 9010b57cec5SDimitry Andrictemplate <typename _Alloc, typename _Traits=allocator_traits<_Alloc> > 9020b57cec5SDimitry Andricstruct __noexcept_move_assign_container : public integral_constant<bool, 9030b57cec5SDimitry Andric _Traits::propagate_on_container_move_assignment::value 9040b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 14 9050b57cec5SDimitry Andric || _Traits::is_always_equal::value 9060b57cec5SDimitry Andric#else 9070b57cec5SDimitry Andric && is_nothrow_move_assignable<_Alloc>::value 9080b57cec5SDimitry Andric#endif 9090b57cec5SDimitry Andric > {}; 9100b57cec5SDimitry Andric 9110b57cec5SDimitry Andric 9120b57cec5SDimitry Andrictemplate <class _Tp, class _Alloc> 9130b57cec5SDimitry Andricstruct __temp_value { 9140b57cec5SDimitry Andric typedef allocator_traits<_Alloc> _Traits; 9150b57cec5SDimitry Andric 9160b57cec5SDimitry Andric typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v; 9170b57cec5SDimitry Andric _Alloc &__a; 9180b57cec5SDimitry Andric 9190b57cec5SDimitry Andric _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); } 9200b57cec5SDimitry Andric _Tp & get() { return *__addr(); } 9210b57cec5SDimitry Andric 9220b57cec5SDimitry Andric template<class... _Args> 9230b57cec5SDimitry Andric _LIBCPP_NO_CFI 9240b57cec5SDimitry Andric __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) { 9250b57cec5SDimitry Andric _Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)), 9260b57cec5SDimitry Andric _VSTD::forward<_Args>(__args)...); 9270b57cec5SDimitry Andric } 9280b57cec5SDimitry Andric 9290b57cec5SDimitry Andric ~__temp_value() { _Traits::destroy(__a, __addr()); } 9300b57cec5SDimitry Andric }; 9310b57cec5SDimitry Andric 9320b57cec5SDimitry Andrictemplate<typename _Alloc, typename = void, typename = void> 9330b57cec5SDimitry Andricstruct __is_allocator : false_type {}; 9340b57cec5SDimitry Andric 9350b57cec5SDimitry Andrictemplate<typename _Alloc> 9360b57cec5SDimitry Andricstruct __is_allocator<_Alloc, 9370b57cec5SDimitry Andric typename __void_t<typename _Alloc::value_type>::type, 938fe6060f1SDimitry Andric typename __void_t<decltype(declval<_Alloc&>().allocate(size_t(0)))>::type 9390b57cec5SDimitry Andric > 9400b57cec5SDimitry Andric : true_type {}; 9410b57cec5SDimitry Andric 9420b57cec5SDimitry Andric// __builtin_new_allocator -- A non-templated helper for allocating and 9430b57cec5SDimitry Andric// deallocating memory using __builtin_operator_new and 9440b57cec5SDimitry Andric// __builtin_operator_delete. It should be used in preference to 9450b57cec5SDimitry Andric// `std::allocator<T>` to avoid additional instantiations. 9460b57cec5SDimitry Andricstruct __builtin_new_allocator { 9470b57cec5SDimitry Andric struct __builtin_new_deleter { 9480b57cec5SDimitry Andric typedef void* pointer_type; 9490b57cec5SDimitry Andric 9500b57cec5SDimitry Andric _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align) 9510b57cec5SDimitry Andric : __size_(__size), __align_(__align) {} 9520b57cec5SDimitry Andric 9530b57cec5SDimitry Andric void operator()(void* p) const _NOEXCEPT { 954e8d8bef9SDimitry Andric _VSTD::__libcpp_deallocate(p, __size_, __align_); 9550b57cec5SDimitry Andric } 9560b57cec5SDimitry Andric 9570b57cec5SDimitry Andric private: 9580b57cec5SDimitry Andric size_t __size_; 9590b57cec5SDimitry Andric size_t __align_; 9600b57cec5SDimitry Andric }; 9610b57cec5SDimitry Andric 9620b57cec5SDimitry Andric typedef unique_ptr<void, __builtin_new_deleter> __holder_t; 9630b57cec5SDimitry Andric 9640b57cec5SDimitry Andric static __holder_t __allocate_bytes(size_t __s, size_t __align) { 965e8d8bef9SDimitry Andric return __holder_t(_VSTD::__libcpp_allocate(__s, __align), 9660b57cec5SDimitry Andric __builtin_new_deleter(__s, __align)); 9670b57cec5SDimitry Andric } 9680b57cec5SDimitry Andric 9690b57cec5SDimitry Andric static void __deallocate_bytes(void* __p, size_t __s, 9700b57cec5SDimitry Andric size_t __align) _NOEXCEPT { 971e8d8bef9SDimitry Andric _VSTD::__libcpp_deallocate(__p, __s, __align); 9720b57cec5SDimitry Andric } 9730b57cec5SDimitry Andric 9740b57cec5SDimitry Andric template <class _Tp> 9750b57cec5SDimitry Andric _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE 9760b57cec5SDimitry Andric static __holder_t __allocate_type(size_t __n) { 9770b57cec5SDimitry Andric return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 9780b57cec5SDimitry Andric } 9790b57cec5SDimitry Andric 9800b57cec5SDimitry Andric template <class _Tp> 9810b57cec5SDimitry Andric _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE 9820b57cec5SDimitry Andric static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT { 9830b57cec5SDimitry Andric __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)); 9840b57cec5SDimitry Andric } 9850b57cec5SDimitry Andric}; 9860b57cec5SDimitry Andric 9870b57cec5SDimitry Andric 9880b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD 9890b57cec5SDimitry Andric 990e40139ffSDimitry Andric#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17 991e40139ffSDimitry Andric# include <__pstl_memory> 992e40139ffSDimitry Andric#endif 993e40139ffSDimitry Andric 9940b57cec5SDimitry Andric#endif // _LIBCPP_MEMORY 995