20 General utilities library [utilities] (original) (raw)
The header <memory> 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, and various function templates that operate on objects of these types ([smartptr]).
#include
namespace std {
template struct pointer_traits; template struct pointer_traits<T*>;
template constexpr T* to_address(T* p) noexcept; template constexpr auto to_address(const Ptr& p) noexcept;
\indexlibraryglobal{in_place}% \indexlibrarymember{relaxed}{pointer_safety}% \indexlibrarymember{preferred}{pointer_safety}% \indexlibrarymember{strict}{pointer_safety} enum class pointer_safety { relaxed, preferred, strict }; void declare_reachable(void* p); template T* undeclare_reachable(T* p); void declare_no_pointers(char* p, size_t n); void undeclare_no_pointers(char* p, size_t n); pointer_safety get_pointer_safety() noexcept;
void* align(size_t alignment, size_t size, void*& ptr, size_t& space); template<size_t N, class T> [[nodiscard]] constexpr T* assume_aligned(T* ptr);
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> inline 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 -> see below; 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 -> see below; template<class T, class Alloc> constexpr auto uses_allocator_construction_args(const Alloc& alloc) noexcept -> see below; template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, U&& u, V&& v) noexcept -> see below; template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, const pair<U,V>& pr) noexcept -> see below; template<class T, class Alloc, class U, class V> constexpr auto uses_allocator_construction_args(const Alloc& alloc, pair<U,V>&& pr) noexcept -> see below; 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 struct allocator_traits;
template class allocator; template<class T, class U> constexpr bool operator==(const allocator&, const allocator&) noexcept;
template constexpr T* addressof(T& r) noexcept; template const T* addressof(const T&&) = delete;
template
concept no-throw-input-iterator = see below;
template
concept no-throw-forward-iterator = see below;
template<class S, class I>
concept no-throw-sentinel = see below;
template
concept no-throw-input-range = see below;
template
concept no-throw-forward-range = see below;
template
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>
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<no-throw-forward-iterator I, no-throw-sentinel S> requires default_initializable<iter_value_t> I uninitialized_default_construct(I first, S last); template requires default_initializable<range_value_t> borrowed_iterator_t uninitialized_default_construct(R&& r);
template<no-throw-forward-iterator I>
requires default_initializable<iter_value_t<I>>
I uninitialized_default_construct_n(I first, iter_difference_t<I> n);}
template
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>
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<no-throw-forward-iterator I, no-throw-sentinel S> requires default_initializable<iter_value_t> I uninitialized_value_construct(I first, S last); template requires default_initializable<range_value_t> borrowed_iterator_t uninitialized_value_construct(R&& r);
template<no-throw-forward-iterator I>
requires default_initializable<iter_value_t<I>>
I uninitialized_value_construct_n(I first, iter_difference_t<I> n);}
template<class InputIterator, class NoThrowForwardIterator>
NoThrowForwardIterator uninitialized_copy(InputIterator first, InputIterator last,
NoThrowForwardIterator result);
template<class ExecutionPolicy, class InputIterator, class NoThrowForwardIterator>
NoThrowForwardIterator uninitialized_copy(ExecutionPolicy&& exec,
InputIterator first, InputIterator last,
NoThrowForwardIterator result);
template<class InputIterator, class Size, class NoThrowForwardIterator>
NoThrowForwardIterator uninitialized_copy_n(InputIterator first, Size n,
NoThrowForwardIterator result);
template<class ExecutionPolicy, class InputIterator, class Size, class NoThrowForwardIterator>
NoThrowForwardIterator uninitialized_copy_n(ExecutionPolicy&& exec,
InputIterator 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 S1, no-throw-forward-iterator O, no-throw-sentinel S2> requires constructible_from<iter_value_t, iter_reference_t> uninitialized_copy_result<I, O> uninitialized_copy(I ifirst, S1 ilast, O ofirst, S2 olast); template<input_range IR, no-throw-forward-range OR> requires constructible_from<range_value_t, range_reference_t> uninitialized_copy_result<borrowed_iterator_t, borrowed_iterator_t> 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, no-throw-forward-iterator O, no-throw-sentinel<O> S>
requires constructible_from<iter_value_t<O>, iter_reference_t<I>>
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>
NoThrowForwardIterator uninitialized_move(InputIterator first, InputIterator last,
NoThrowForwardIterator result);
template<class ExecutionPolicy, class InputIterator, class NoThrowForwardIterator>
NoThrowForwardIterator uninitialized_move(ExecutionPolicy&& exec,
InputIterator first, InputIterator last,
NoThrowForwardIterator result);
template<class InputIterator, class Size, class NoThrowForwardIterator>
pair<InputIterator, NoThrowForwardIterator>
uninitialized_move_n(InputIterator first, Size n, NoThrowForwardIterator result);
template<class ExecutionPolicy, class InputIterator, class Size, class NoThrowForwardIterator>
pair<InputIterator, NoThrowForwardIterator>
uninitialized_move_n(ExecutionPolicy&& exec,
InputIterator 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 S1, no-throw-forward-iterator O, no-throw-sentinel S2> requires constructible_from<iter_value_t, iter_rvalue_reference_t> uninitialized_move_result<I, O> uninitialized_move(I ifirst, S1 ilast, O ofirst, S2 olast); template<input_range IR, no-throw-forward-range OR> requires constructible_from<range_value_t, range_rvalue_reference_t> uninitialized_move_result<borrowed_iterator_t, borrowed_iterator_t> 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,
no-throw-forward-iterator O, no-throw-sentinel<O> S>
requires constructible_from<iter_value_t<O>, iter_rvalue_reference_t<I>>
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>
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>
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<no-throw-forward-iterator I, no-throw-sentinel S, class T> requires constructible_from<iter_value_t, const T&> I uninitialized_fill(I first, S last, const T& x); template<no-throw-forward-range R, class T> requires constructible_from<range_value_t, const T&> borrowed_iterator_t uninitialized_fill(R&& r, const T& x);
template<no-throw-forward-iterator I, class T>
requires constructible_from<iter_value_t<I>, const T&>
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
constexpr void destroy_at(T* location);
template
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 constexpr void destroy_at(T* location) noexcept;
template<no-throw-input-iterator I, no-throw-sentinel<I> S>
requires destructible<iter_value_t<I>>
constexpr I destroy(I first, S last) noexcept;
template<no-throw-input-range R>
requires destructible<range_value_t<R>>
constexpr borrowed_iterator_t<R> destroy(R&& r) noexcept;
template<no-throw-input-iterator I>
requires destructible<iter_value_t<I>>
constexpr I destroy_n(I first, iter_difference_t<I> n) noexcept;}
template struct default_delete; template struct default_delete<T[]>; template<class T, class D = default_delete> class unique_ptr; template<class T, class D> class unique_ptr<T[], D>;
template<class T, class... Args>
unique_ptr make_unique(Args&&... args);
template
unique_ptr make_unique(size_t n);
template<class T, class... Args>
unspecified make_unique(Args&&...) = delete;
template
unique_ptr make_unique_for_overwrite();
template
unique_ptr make_unique_for_overwrite(size_t n);
template<class T, class... Args>
unspecified make_unique_for_overwrite(Args&&...) = delete;
template<class T, class D> void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
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> 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> bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept; template<class T, class D> bool operator<(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> bool operator<(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> bool operator>(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> bool operator>(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> bool operator<=(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> bool operator<=(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> bool operator>=(const unique_ptr<T, D>& x, nullptr_t); template<class T, class D> bool operator>=(nullptr_t, const unique_ptr<T, D>& y); template<class T, class D> requires three_way_comparable_with<typename unique_ptr<T, D>::pointer, nullptr_t> compare_three_way_result_t<typename unique_ptr<T, D>::pointer, nullptr_t> 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 shared_ptr;
template<class T, class... Args>
shared_ptr make_shared(Args&&... args);
template<class T, class A, class... Args>
shared_ptr allocate_shared(const A& a, Args&&... args);
template
shared_ptr make_shared(size_t N);
template<class T, class A>
shared_ptr allocate_shared(const A& a, size_t N);
template
shared_ptr make_shared();
template<class T, class A>
shared_ptr allocate_shared(const A& a);
template
shared_ptr make_shared(size_t N, const remove_extent_t& u);
template<class T, class A>
shared_ptr allocate_shared(const A& a, size_t N,
const remove_extent_t& u);
template
shared_ptr make_shared(const remove_extent_t& u);
template<class T, class A>
shared_ptr allocate_shared(const A& a, const remove_extent_t& u);
template
shared_ptr make_shared_for_overwrite();
template<class T, class A>
shared_ptr allocate_shared_for_overwrite(const A& a);
template
shared_ptr make_shared_for_overwrite(size_t N);
template<class T, class A>
shared_ptr allocate_shared_for_overwrite(const A& a, size_t N);
template<class T, class U> bool operator==(const shared_ptr& a, const shared_ptr& b) noexcept; template<class T, class U> strong_ordering operator<=>(const shared_ptr& a, const shared_ptr& b) noexcept;
template bool operator==(const shared_ptr& x, nullptr_t) noexcept; template strong_ordering operator<=>(const shared_ptr& x, nullptr_t) noexcept;
template void swap(shared_ptr& a, shared_ptr& b) noexcept;
template<class T, class U> shared_ptr static_pointer_cast(const shared_ptr& r) noexcept; template<class T, class U> shared_ptr static_pointer_cast(shared_ptr&& r) noexcept; template<class T, class U> shared_ptr dynamic_pointer_cast(const shared_ptr& r) noexcept; template<class T, class U> shared_ptr dynamic_pointer_cast(shared_ptr&& r) noexcept; template<class T, class U> shared_ptr const_pointer_cast(const shared_ptr& r) noexcept; template<class T, class U> shared_ptr const_pointer_cast(shared_ptr&& r) noexcept; template<class T, class U> shared_ptr reinterpret_pointer_cast(const shared_ptr& r) noexcept; template<class T, class U> shared_ptr reinterpret_pointer_cast(shared_ptr&& r) noexcept;
template<class D, class T> D* get_deleter(const shared_ptr& p) noexcept;
template<class E, class T, class Y> basic_ostream<E, T>& operator<<(basic_ostream<E, T>& os, const shared_ptr& p);
template class weak_ptr;
template void swap(weak_ptr& a, weak_ptr& b) noexcept;
template struct owner_less;
template class enable_shared_from_this;
template struct hash; template<class T, class D> struct hash<unique_ptr<T, D>>; template struct hash<shared_ptr>;
template struct atomic; template struct atomic<shared_ptr>; template struct atomic<weak_ptr>; }