Small opaque type-erased type with configurable small buffer optimization.
More...
#include <Acts/Utilities/Any.hpp>
|
| | AnyBase ()=default |
| | AnyBase (AnyBase &&other) _ACTS_ANY_NOEXCEPT |
| | Move constructor.
|
| | AnyBase (const AnyBase &other) _ACTS_ANY_NOEXCEPT |
| | Copy constructor.
|
template<typename T, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>))) |
| | AnyBase (std::in_place_type_t< T >, Args &&... args) |
| | Construct with in-place type construction.
|
template<typename T>
requires (!std::same_as<std::decay_t<T>, AnyBase<SIZE>> && std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>))) |
| | AnyBase (T &&value) _ACTS_ANY_NOEXCEPT |
| | Construct from any value type.
|
| | ~AnyBase () |
| 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, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<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) _ACTS_ANY_NOEXCEPT |
| | Move assignment operator.
|
| AnyBase & | operator= (const AnyBase &other) _ACTS_ANY_NOEXCEPT |
| | Copy assignment operator.
|
template<std::size_t SIZE>
class Acts::AnyBase< SIZE >
Small opaque type-erased type with configurable small buffer optimization.
- Note
- Type requirements:
- All stored types must be copy constructible and copy assignable.
- Types stored locally (sizeof(T) <= 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) > SIZE) are moved by stealing the pointer, so no move operations are required in that case.
-
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.
◆ AnyBase() [1/5]
template<std::size_t SIZE>
template<typename T, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
| Acts::AnyBase< SIZE >::AnyBase |
( |
std::in_place_type_t< T > | , |
|
|
Args &&... | args ) |
|
explicit |
Construct with in-place type construction.
- Template Parameters
-
| T | Type to construct |
| Args | Constructor argument types |
- Parameters
-
| args | Arguments to forward to T's constructor |
◆ AnyBase() [2/5]
template<std::size_t SIZE>
◆ AnyBase() [3/5]
template<std::size_t SIZE>
template<typename T>
requires (!std::same_as<std::decay_t<T>, AnyBase<SIZE>> && std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
Construct from any value type.
- Template Parameters
-
| T | Type of the value to store |
- Parameters
-
| value | Value to store in the Any |
◆ ~AnyBase()
template<std::size_t SIZE>
◆ AnyBase() [4/5]
template<std::size_t SIZE>
Copy constructor.
- Parameters
-
| other | The AnyBase to copy from |
◆ AnyBase() [5/5]
template<std::size_t SIZE>
Move constructor.
- Parameters
-
| other | The AnyBase to move from |
◆ as() [1/2]
template<std::size_t SIZE>
template<typename T>
Get reference to stored value of specified type.
- Template Parameters
-
| T | Type to retrieve (must be exact type, no const/ref) |
- Returns
- Reference to the stored value
- Exceptions
-
| std::bad_any_cast | if stored type doesn't match T |
◆ as() [2/2]
template<std::size_t SIZE>
template<typename T>
Get const reference to stored value of specified type.
- Template Parameters
-
| T | Type to retrieve (must be exact type, no const/ref) |
- Returns
- Const reference to the stored value
- Exceptions
-
| std::bad_any_cast | if stored type doesn't match T |
◆ emplace()
template<std::size_t SIZE>
template<typename T, typename... Args>
requires (std::is_copy_assignable_v<std::decay_t<T>> && std::is_copy_constructible_v<std::decay_t<T>> && (sizeof(std::decay_t<T>) > SIZE || (std::is_move_assignable_v<std::decay_t<T>> && std::is_move_constructible_v<std::decay_t<T>>)))
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
◆ operator bool()
template<std::size_t SIZE>
Check if the AnyBase contains a value.
- Returns
- True if a value is stored, false if empty
◆ operator=() [1/2]
template<std::size_t SIZE>
Move assignment operator.
- Parameters
-
| other | The AnyBase to move from |
- Returns
- Reference to this object
◆ operator=() [2/2]
template<std::size_t SIZE>
Copy assignment operator.
- Parameters
-
| other | The AnyBase to copy from |
- Returns
- Reference to this object