indirect
Declared in <folly/Indirect.h>
template<
typename T,
typename Alloc = std::allocator<T>>
class indirect;
An owning, heap-allocated, deep-copy value wrapper for T, usable without a C++26 toolchain. The member set matches [indirect.syn]exactly, so code written against folly::indirect ports to std::indirect unchanged.
indirect always owns a value (never empty) except for a valueless state produced by moving from an indirect or by constructing or assigning from a valueless source. A valueless indirect supports destruction, assignment, valueless_after_move(), equality/ordering comparisons and hashing; operator* and operator-> assert in debug and are UB in release when valueless.
Allocator-aware: Alloc must have value_type == T and is used directly without rebinding. Copy/move assignment and swap respect allocator_traits<Alloc>::propagate_on_container_*.
mimic: std::indirect, C++26, P1950R2, P3019R4
| Name | Description |
|---|---|
allocator_type | Allocator type used for the owned value. |
const_pointer | Const pointer to the owned value. |
pointer | Pointer to the owned value. |
value_type | Type of the owned value. |
| Name | Description |
|---|---|
indirect [constructor] | Constructors |
~indirect [destructor] | Destroys the owned value, if any. |
operator= | Assignment operators |
get_allocator | Returns a copy of the allocator. |
operator* | Accesses the owned value. |
operator-> | Accesses the owned value's members. |
swap | Swaps the owned values (and allocators when they propagate on swap). |
valueless_after_move | Tests whether the wrapper is in the valueless (moved-from) state. |
| Name | Description |
|---|---|
indirect<T> | Deduces indirect<T> from a value of type T. |
indirect<Value, std::allocator_traits<Alloc>::rebind_alloc<Value>> | Deduces the allocator-aware indirect from an allocator and a value, rebinding the allocator to the value type. |
| Name | Description |
|---|---|
folly::operator<=> | Orders a wrapper against a value. |
folly::operator== | Compares a wrapper with a value for equality. |
folly::operator<=> | Orders two wrappers by their owned values. |
folly::operator== | Compares two wrappers for equality by their owned values. |
folly::swap | Swaps two wrappers. |