20 Memory management library [mem] (original) (raw)
The header defines several types and function templates that describe properties of pointers and pointer-like types, manage memory for containers and other template types, destroy objects, and construct objects in uninitialized memory buffers ([pointer.traits]–[specialized.addressof] and [specialized.algorithms]).
The header also defines the templatesunique_ptr, shared_ptr, weak_ptr,out_ptr_t, inout_ptr_t, and various function templates that operate on objects of these types ([smartptr]).
Let POINTER_OF(T) denote a type that is
- T::pointer if the qualified-id T::pointeris valid and denotes a type,
- otherwise, T::element_type*if the qualified-id T::element_typeis valid and denotes a type,
- otherwise, pointer_traits<T>::element_type*.
Let POINTER_OF_OR(T, U) denote a type that is:
- POINTER_OF(T)if POINTER_OF(T) is valid and denotes a type,
- otherwise, U.
#include <compare> namespace std { template<class Ptr> struct pointer_traits; template<class T> struct pointer_traits<T*>; template<class T> constexpr T* to_address(T* p) noexcept; template<class Ptr> constexpr auto to_address(const Ptr& p) noexcept; void* align(size_t alignment, size_t size, void*& ptr, size_t& space); template<size_t N, class T> constexpr T* assume_aligned(T* ptr); template<size_t Alignment, class T> bool is_sufficiently_aligned(T* ptr);template<class T> T* start_lifetime_as(void* p) noexcept; template<class T> const T* start_lifetime_as(const void* p) noexcept; template<class T> volatile T* start_lifetime_as(volatile void* p) noexcept; template<class T> const volatile T* start_lifetime_as(const volatile void* p) noexcept; template<class T> T* start_lifetime_as_array(void* p, size_t n) noexcept; template<class T> const T* start_lifetime_as_array(const void* p, size_t n) noexcept; template<class T> volatile T* start_lifetime_as_array(volatile void* p, size_t n) noexcept; template<class T> const volatile T* start_lifetime_as_array(const volatile void* p, size_t n) noexcept;template<class T> T* trivially_relocate(T* first, T* last, T* result); template<class T> constexpr T* relocate(T* first, T* last, T* result); struct allocator_arg_t { explicit allocator_arg_t() = default; }; inline constexpr allocator_arg_t allocator_arg{}; template<class T, class Alloc> struct uses_allocator; template<class T, class Alloc> constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value; template<class T, class Alloc, class... Args> constexpr auto uses_allocator_construction_args(const Alloc& alloc, Args&&... args) noexcept;template<class T, class Alloc, class Tuple1, class Tuple2> constexpr auto uses_allocator_construction_args(const Alloc& alloc, piecewise_construct_t, Tuple1&& x, Tuple2&& y) noexcept;template<class T, class Alloc> constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept; template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, U&& u, V&& v) noexcept;template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, pair<U, V>& pr) noexcept;template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, const pair<U, V>& pr) noexcept;template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, pair<U, V>&& pr) noexcept;template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, const pair<U, V>&& pr) noexcept;template<class T, class Alloc, pair-like P> constexpr auto uses_allocator_construction_args(const Alloc& alloc, P&& p) noexcept;template<class T, class Alloc, class U> constexpr auto uses_allocator_construction_args(const Alloc& alloc, U&& u) noexcept;template<class T, class Alloc, class... Args> constexpr T make_obj_using_allocator(const Alloc& alloc, Args&&... args); template<class T, class Alloc, class... Args> constexpr T* uninitialized_construct_using_allocator(T* p, const Alloc& alloc, Args&&... args);template<class Alloc> struct allocator_traits; template<class Pointer, class SizeType = size_t> struct allocation_result { Pointer ptr; SizeType count;};template<class T> class allocator;template<class T, class U> constexpr bool operator==(const allocator<T>&, const allocator<U>&) noexcept;template<class T> constexpr T* addressof(T& r) noexcept; template<class T> const T* addressof(const T&&) = delete; template<class I> concept nothrow-input-iterator = see below; template<class I> concept nothrow-forward-iterator = see below; template<class S, class I> concept nothrow-sentinel-for = see below; template<class R> concept nothrow-input-range = see below; template<class R> concept nothrow-forward-range = see below; template<class NoThrowForwardIterator> constexpr void uninitialized_default_construct(NoThrowForwardIterator first, NoThrowForwardIterator last);template<class ExecutionPolicy, class NoThrowForwardIterator> void uninitialized_default_construct(ExecutionPolicy&& exec, NoThrowForwardIterator first, NoThrowForwardIterator last);template<class NoThrowForwardIterator, class Size> constexpr NoThrowForwardIterator uninitialized_default_construct_n(NoThrowForwardIterator first, Size n); template<class ExecutionPolicy, class NoThrowForwardIterator, class Size> NoThrowForwardIterator uninitialized_default_construct_n(ExecutionPolicy&& exec, NoThrowForwardIterator first, Size n);namespace ranges { template<nothrow-forward-iterator I, nothrow-sentinel-for<I> S> requires default_initializable<iter_value_t<I>> constexpr I uninitialized_default_construct(I first, S last); template<nothrow-forward-range R> requires default_initializable<range_value_t<R>> constexpr borrowed_iterator_t<R> uninitialized_default_construct(R&& r); template<nothrow-forward-iterator I> requires default_initializable<iter_value_t<I>> constexpr I uninitialized_default_construct_n(I first, iter_difference_t<I> n);} template<class NoThrowForwardIterator> constexpr void uninitialized_value_construct(NoThrowForwardIterator first, NoThrowForwardIterator last);template<class ExecutionPolicy, class NoThrowForwardIterator> void uninitialized_value_construct(ExecutionPolicy&& exec, NoThrowForwardIterator first, NoThrowForwardIterator last);template<class NoThrowForwardIterator, class Size> constexpr NoThrowForwardIterator uninitialized_value_construct_n(NoThrowForwardIterator first, Size n); template<class ExecutionPolicy, class NoThrowForwardIterator, class Size> NoThrowForwardIterator uninitialized_value_construct_n(ExecutionPolicy&& exec, NoThrowForwardIterator first, Size n);namespace ranges { template<nothrow-forward-iterator I, nothrow-sentinel-for<I> S> requires default_initializable<iter_value_t<I>> constexpr I uninitialized_value_construct(I first, S last); template<nothrow-forward-range R> requires default_initializable<range_value_t<R>> constexpr borrowed_iterator_t<R> uninitialized_value_construct(R&& r); template<nothrow-forward-iterator I> requires default_initializable<iter_value_t<I>> constexpr I uninitialized_value_construct_n(I first, iter_difference_t<I> n);} template<class InputIterator, class NoThrowForwardIterator> constexpr NoThrowForwardIterator uninitialized_copy(InputIterator first, InputIterator last, NoThrowForwardIterator result);template<class ExecutionPolicy, class ForwardIterator, class NoThrowForwardIterator> NoThrowForwardIterator uninitialized_copy(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, NoThrowForwardIterator result);template<class InputIterator, class Size, class NoThrowForwardIterator> constexpr NoThrowForwardIterator uninitialized_copy_n(InputIterator first, Size n, NoThrowForwardIterator result);template<class ExecutionPolicy, class ForwardIterator, class Size,class NoThrowForwardIterator> NoThrowForwardIterator uninitialized_copy_n(ExecutionPolicy&& exec, ForwardIterator first, Size n, NoThrowForwardIterator result);namespace ranges { template<class I, class O> using uninitialized_copy_result = in_out_result<I, O>; template<input_iterator I, sentinel_for<I> S1,nothrow-forward-iterator O, nothrow-sentinel-for<O> S2> requires constructible_from<iter_value_t<O>, iter_reference_t<I>> constexpr uninitialized_copy_result<I, O> uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast); template<input_range IR, nothrow-forward-range OR> requires constructible_from<range_value_t<OR>, range_reference_t<IR>> constexpr uninitialized_copy_result<borrowed_iterator_t<IR>, borrowed_iterator_t<OR>> uninitialized_copy(IR&& in_range, OR&& out_range); template<class I, class O> using uninitialized_copy_n_result = in_out_result<I, O>; template<input_iterator I, nothrow-forward-iterator O, nothrow-sentinel-for<O> S> requires constructible_from<iter_value_t<O>, iter_reference_t<I>> constexpr uninitialized_copy_n_result<I, O> uninitialized_copy_n(I ifirst, iter_difference_t<I> n, O ofirst, S olast);} template<class InputIterator, class NoThrowForwardIterator> constexpr NoThrowForwardIterator uninitialized_move(InputIterator first, InputIterator last, NoThrowForwardIterator result);template<class ExecutionPolicy, class ForwardIterator, class NoThrowForwardIterator> NoThrowForwardIterator uninitialized_move(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, NoThrowForwardIterator result);template<class InputIterator, class Size, class NoThrowForwardIterator> constexpr pair<InputIterator, NoThrowForwardIterator> uninitialized_move_n(InputIterator first, Size n, NoThrowForwardIterator result);template<class ExecutionPolicy, class ForwardIterator, class Size,class NoThrowForwardIterator> pair<ForwardIterator, NoThrowForwardIterator> uninitialized_move_n(ExecutionPolicy&& exec, ForwardIterator first, Size n, NoThrowForwardIterator result);namespace ranges { template<class I, class O> using uninitialized_move_result = in_out_result<I, O>; template<input_iterator I, sentinel_for<I> S1,nothrow-forward-iterator O, nothrow-sentinel-for<O> S2> requires constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>> constexpr uninitialized_move_result<I, O> uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast); template<input_range IR, nothrow-forward-range OR> requires constructible_from<range_value_t<OR>, range_rvalue_reference_t<IR>> constexpr uninitialized_move_result<borrowed_iterator_t<IR>, borrowed_iterator_t<OR>> uninitialized_move(IR&& in_range, OR&& out_range); template<class I, class O> using uninitialized_move_n_result = in_out_result<I, O>; template<input_iterator I,nothrow-forward-iterator O, nothrow-sentinel-for<O> S> requires constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>> constexpr uninitialized_move_n_result<I, O> uninitialized_move_n(I ifirst, iter_difference_t<I> n, O ofirst, S olast);} template<class NoThrowForwardIterator, class T> constexpr void uninitialized_fill(NoThrowForwardIterator first, NoThrowForwardIterator last, const T& x);template<class ExecutionPolicy, class NoThrowForwardIterator, class T> void uninitialized_fill(ExecutionPolicy&& exec, NoThrowForwardIterator first, NoThrowForwardIterator last,const T& x);template<class NoThrowForwardIterator, class Size, class T> constexpr NoThrowForwardIterator uninitialized_fill_n(NoThrowForwardIterator first, Size n, const T& x); template<class ExecutionPolicy, class NoThrowForwardIterator, class Size, class T> NoThrowForwardIterator uninitialized_fill_n(ExecutionPolicy&& exec, NoThrowForwardIterator first, Size n, const T& x);namespace ranges { template<nothrow-forward-iterator I, nothrow-sentinel-for<I> S, class T> requires constructible_from<iter_value_t<I>, const T&> constexpr I uninitialized_fill(I first, S last, const T& x); template<nothrow-forward-range R, class T> requires constructible_from<range_value_t<R>, const T&> constexpr borrowed_iterator_t<R> uninitialized_fill(R&& r, const T& x); template<nothrow-forward-iterator I, class T> requires constructible_from<iter_value_t<I>, const T&> constexpr I uninitialized_fill_n(I first, iter_difference_t<I> n, const T& x);} template<class T, class... Args> constexpr T* construct_at(T* location, Args&&... args); namespace ranges { template<class T, class... Args> constexpr T* construct_at(T* location, Args&&... args); } template<class T> constexpr void destroy_at(T* location); template<class NoThrowForwardIterator> constexpr void destroy(NoThrowForwardIterator first, NoThrowForwardIterator last);template<class ExecutionPolicy, class NoThrowForwardIterator> void destroy(ExecutionPolicy&& exec, NoThrowForwardIterator first, NoThrowForwardIterator last);template<class NoThrowForwardIterator, class Size> constexpr NoThrowForwardIterator destroy_n(NoThrowForwardIterator first, Size n);template<class ExecutionPolicy, class NoThrowForwardIterator, class Size> NoThrowForwardIterator destroy_n(ExecutionPolicy&& exec, NoThrowForwardIterator first, Size n); namespace ranges { template<destructible T> constexpr void destroy_at(T* location) noexcept; template<nothrow-input-iterator I, nothrow-sentinel-for<I> S> requires destructible<iter_value_t<I>> constexpr I destroy(I first, S last) noexcept; template<nothrow-input-range R> requires destructible<range_value_t<R>> constexpr borrowed_iterator_t<R> destroy(R&& r) noexcept; template<nothrow-input-iterator I> requires destructible<iter_value_t<I>> constexpr I destroy_n(I first, iter_difference_t<I> n) noexcept; } template<class T> struct default_delete; template<class T> struct default_delete<T[]>; template<class T, class D = default_delete<T>> class unique_ptr; template<class T, class D> class unique_ptr<T[], D>; template<class T, class... Args> constexpr unique_ptr<T> make_unique(Args&&... args); template<class T> constexpr unique_ptr<T> make_unique(size_t n); template<class T, class... Args> unspecified make_unique(Args&&...) = delete; template<class T> constexpr unique_ptr<T> make_unique_for_overwrite(); template<class T> constexpr unique_ptr<T> make_unique_for_overwrite(size_t n); template<class T, class... Args> unspecified make_unique_for_overwrite(Args&&...) = delete; template<class T, class D> constexpr void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept; template<class T1, class D1, class T2, class D2> constexpr bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);template<class T1, class D1, class T2, class D2> bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); template<class T1, class D1, class T2, class D2> bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); template<class T1, class D1, class T2, class D2> bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); template<class T1, class D1, class T2, class D2> bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); template<class T1, class D1, class T2, class D2> requires three_way_comparable_with<typename unique_ptr<T1, D1>::pointer,typename unique_ptr<T2, D2>::pointer> compare_three_way_result_t<typename unique_ptr<T1, D1>::pointer,typename unique_ptr<T2, D2>::pointer> operator<=>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y); template<class T, class D> constexpr bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; template<class T, class D> constexpr bool operator<(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> constexpr bool operator<(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> constexpr bool operator>(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> constexpr bool operator>(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> constexpr bool operator<=(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> constexpr bool operator<=(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> constexpr bool operator>=(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> constexpr bool operator>=(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> requires three_way_comparable<typename unique_ptr<T, D>::pointer> constexpr compare_three_way_result_t<typename unique_ptr<T, D>::pointer> operator<=>(const unique_ptr<T, D>& x, nullptr_t); template<class E, class T, class Y, class D> basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const unique_ptr<Y, D>& p);class bad_weak_ptr;template<class T> class shared_ptr;template<class T, class... Args> shared_ptr<T> make_shared(Args&&... args); template<class T, class A, class... Args> shared_ptr<T> allocate_shared(const A& a, Args&&... args); template<class T> shared_ptr<T> make_shared(size_t N); template<class T, class A> shared_ptr<T> allocate_shared(const A& a, size_t N); template<class T> shared_ptr<T> make_shared(); template<class T, class A> shared_ptr<T> allocate_shared(const A& a); template<class T> shared_ptr<T> make_shared(size_t N, const remove_extent_t<T>& u); template<class T, class A> shared_ptr<T> allocate_shared(const A& a, size_t N,const remove_extent_t<T>& u); template<class T> shared_ptr<T> make_shared(const remove_extent_t<T>& u); template<class T, class A> shared_ptr<T> allocate_shared(const A& a, const remove_extent_t<T>& u); template<class T> shared_ptr<T> make_shared_for_overwrite(); template<class T, class A> shared_ptr<T> allocate_shared_for_overwrite(const A& a); template<class T> shared_ptr<T> make_shared_for_overwrite(size_t N); template<class T, class A> shared_ptr<T> allocate_shared_for_overwrite(const A& a, size_t N); template<class T, class U> bool operator==(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;template<class T, class U> strong_ordering operator<=>(const shared_ptr<T>& a, const shared_ptr<U>& b) noexcept;template<class T> bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;template<class T> strong_ordering operator<=>(const shared_ptr<T>& x, nullptr_t) noexcept;template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;template<class T, class U> shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r) noexcept;template<class T, class U> shared_ptr<T> static_pointer_cast(shared_ptr<U>&& r) noexcept;template<class T, class U> shared_ptr<T> dynamic_pointer_cast(const shared_ptr<U>& r) noexcept;template<class T, class U> shared_ptr<T> dynamic_pointer_cast(shared_ptr<U>&& r) noexcept;template<class T, class U> shared_ptr<T> const_pointer_cast(const shared_ptr<U>& r) noexcept;template<class T, class U> shared_ptr<T> const_pointer_cast(shared_ptr<U>&& r) noexcept;template<class T, class U> shared_ptr<T> reinterpret_pointer_cast(const shared_ptr<U>& r) noexcept;template<class T, class U> shared_ptr<T> reinterpret_pointer_cast(shared_ptr<U>&& r) noexcept;template<class D, class T> D* get_deleter(const shared_ptr<T>& p) noexcept;template<class E, class T, class Y> basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const shared_ptr<Y>& p);template<class T> class weak_ptr;template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;template<class T = void> struct owner_less;struct owner_hash;struct owner_equal;template<class T> class enable_shared_from_this;template<class T> struct hash; template<class T, class D> struct hash<unique_ptr<T, D>>; template<class T> struct hash<shared_ptr<T>>;template<class T> struct atomic; template<class T> struct atomic<shared_ptr<T>>;template<class T> struct atomic<weak_ptr<T>>;template<class Smart, class Pointer, class... Args> class out_ptr_t; template<class Pointer = void, class Smart, class... Args> auto out_ptr(Smart& s, Args&&... args); template<class Smart, class Pointer, class... Args> class inout_ptr_t; template<class Pointer = void, class Smart, class... Args> auto inout_ptr(Smart& s, Args&&... args); template<class T, class Allocator = allocator<T>> class indirect;template<class T, class Alloc> struct hash<indirect<T, Alloc>>;template<class T, class Allocator = allocator<T>> class polymorphic;namespace pmr { template<class T> using indirect = indirect<T, polymorphic_allocator<T>>;template<class T> using polymorphic = polymorphic<T, polymorphic_allocator<T>>;} }