Spec-Zone.ru › C++

std::indirect

Defined in header <memory>
template< class T, class Allocator = std::allocator<T> >
class indirect;
(1) (since C++26)
namespace pmr {
    template< class T >
    using indirect = std::indirect<T, std::pmr::polymorphic_allocator<T>>;
}
(2) (since C++26)
1) std::indirect is a wrapper containing dynamically-allocated object with value-like semantics.
2) std::pmr::indirect is an alias template that uses a polymorphic allocator.

An std::indirect object manages the lifetime of an owned object. An std::indirect object can only have no owned object after it has been moved from, in this case it is valueless .

Every object of type std::indirect<T, Allocator> uses an object of type Allocator to allocate and free storage for the owned object as needed.

If a program declares an explicit or partial specialization of std::indirect, the behavior is undefined.

Template parameters

T - the type of the owned object
Allocator - the type of the associated allocator
Type requirements
-T may be an incomplete type.
-If T is one of the following types, the program is ill-formed:
  • a non-object type
  • an array type
  • std::in_place_t
  • a specialization of std::in_place_type_t
  • a cv-qualified type
-If Allocator does not satisfy the requirements of Allocator, the program is ill-formed.
-If std::allocator_traits<Allocator>::value_type is not the same type as T, the program is ill-formed.

Nested types

Type Definition
value_type T
allocator_type Allocator
pointer typenamestd::allocator_traits<Allocator>::pointer
const_pointer typenamestd::allocator_traits<Allocator>::const_pointer

Data members

Member Description
pointer p a pointer to the owned value
(exposition-only member object*)
Allocator alloc the asociated allocator
(exposition-only member object*)

Member functions

(constructor)
constructs the indirect object
(public member function)
(destructor)
destroys the owned value, if there is one
(public member function)
operator=
assigns contents
(public member function)
Observers
operator->operator*
accesses the owned value
(public member function)
valueless_after_move
checks if the indirect is valueless
(public member function)
get_allocator
returns the associated allocator
(public member function)
Modifiers
swap
exchanges the contents
(public member function)

Non-member functions

operator==operator<=>
(C++26)(C++26)
compares indirect objects
(function template)
std::swap(std::indirect)
(C++26)
specializes the std::swap algorithm
(function template)

Helper classes

std::hash<std::indirect>
(C++26)
hash support for std::indirect
(class template specialization)

Deduction guides

Notes

Feature-test macro Value Std Feature
__cpp_lib_indirect 202502L (C++26) std::indirect

Example

See also

polymorphic
(C++26)
a polymorphic wrapper containing dynamically-allocated object with value-like semantics
(class template)
unique_ptr
(C++11)
smart pointer with unique object ownership semantics
(class template)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/cpp/memory/indirect

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API