|
| | AnyBase (AnyBase &&other) noexcept(detail::kAnyNoexcept) |
| | Move constructor.
|
|
| AnyBase (const AnyBase &)=delete |
| | Copy constructor deleted when copyable is false (move-only variant).
|
| | AnyBase (const AnyBase &other) noexcept(detail::kAnyNoexcept) |
| | Copy constructor (only when copyable is true).
|
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>()) |
| | AnyBase (std::in_place_type_t< T >, Args &&... args) |
| | Construct with in-place type construction.
|
template<typename T>
requires (isStorable<std::decay_t<T>>()) |
| | AnyBase (T &&value) noexcept(detail::kAnyNoexcept) |
| | Construct from any value type.
|
| template<typename T> |
| T & | as () |
| | Get reference to stored value of specified type.
|
| template<typename T> |
| const T & | as () const |
| | Get const reference to stored value of specified type.
|
| template<typename T> |
| T * | asPtr () |
| | Get pointer to stored value of specified type.
|
| template<typename T> |
| const T * | asPtr () const |
| | Get const pointer to stored value of specified type.
|
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>()) |
| T & | emplace (Args &&... args) |
| | Construct a new value in place, destroying any existing value.
|
| | operator bool () const |
| | Check if the AnyBase contains a value.
|
| AnyBase & | operator= (AnyBase &&other) noexcept(detail::kAnyNoexcept) |
| | Move assignment operator.
|
|
AnyBase & | operator= (const AnyBase &)=delete |
| | Copy assignment deleted when copyable is false (move-only variant).
|
| AnyBase & | operator= (const AnyBase &other) noexcept(detail::kAnyNoexcept) |
| | Copy assignment operator (only when copyable is true).
|
| template<typename T> |
| T | take () |
| | Move the stored value out.
|
| const std::type_info * | typeInfo () const |
| | Type info of the stored value.
|
template<std::size_t sb_size, bool copyable = true>
class Acts::AnyBase< sb_size, copyable >
Small opaque type-erased type with configurable small buffer optimization.
- Template Parameters
-
| sb_size | Size of the internal buffer for small buffer optimization |
| copyable | If true, stored types must be copyable and AnyBase is copyable. If false, move-only types are allowed and AnyBase is move-only (copy constructor and copy assignment are deleted). |
- Note
- Type requirements when copyable is true:
- All stored types must be copy constructible and copy assignable.
- Types stored locally (sizeof(T) <= sb_size) must also be move constructible and move assignable because local moves use move operations when not trivially movable (trivial moves fall back to buffer copies).
- Types stored on the heap (sizeof(T) > sb_size) are moved by stealing the pointer, so no move operations are required in that case.
-
Type requirements when copyable is false:
- All stored types must be move constructible.
- Types stored locally must also be move assignable.
- Heap-allocated types only need move constructible (pointer steal).
-
In summary:
- Local storage: values live inside the internal buffer; moves may invoke move operations or buffer copies; copies use copy operations or buffer copies when trivial.
- Heap storage: values are allocated on the heap; moves transfer ownership of the pointer; copies allocate and copy-construct the pointee.
template<std::size_t sb_size, bool copyable = true>
template<typename T, typename... Args>
requires (isStorable<std::decay_t<T>>())
| T & Acts::AnyBase< sb_size, copyable >::emplace |
( |
Args &&... | args | ) |
|
Construct a new value in place, destroying any existing value.
- Template Parameters
-
| T | Type to construct |
| Args | Constructor argument types |
- Parameters
-
| args | Arguments to forward to T's constructor |
- Returns
- Reference to the newly constructed value