|
| constexpr | AnyBase () noexcept |
| | Construct an empty wrapper.
|
template<typename T>
requires (!std::is_same_v<std::decay_t<T>, AnyBase>) |
| | AnyBase (T &&value) |
| | Construct a wrapper from a value.
|
| | ~AnyBase () |
| | Destructor.
|
| | AnyBase (const AnyBase &other) |
| | Copy constructor.
|
| | AnyBase (AnyBase &&other) noexcept |
| | Move constructor.
|
| AnyBase & | operator= (const AnyBase &other) |
| | Copy assignment.
|
| AnyBase & | operator= (AnyBase &&other) noexcept |
| | Move assignment.
|
| void | reset () noexcept |
| | Destroy the wrapped object if one exists, and reset the wrapper to empty.
|
| template<typename T, typename... Args> |
| std::decay_t< T > & | emplace (Args &&... args) |
| | Destroy the wrapped object if one exists, then replace it with a new object.
|
| Base * | base () noexcept |
| | Get a base pointer to the wrapped value.
|
| const Base * | base () const noexcept |
| | Get a base pointer to the wrapped value.
|
| Base * | getUnsafeSmallObjectBasePointer () |
| | Get a base pointer to the wrapped value, under the assumption that the value currently held by the wrapper fits into the small object optimization (in both size and alignment), and also that its address can be safely cast to the base pointer type without applying any offset (which can only be true if the concrete value type only has one base class, and the base class is not virtual).
|
| const Base * | getUnsafeSmallObjectBasePointer () const |
| | Get a base pointer to the wrapped value, under the assumption that the value currently held by the wrapper fits into the small object optimization (in both size and alignment), and also that its address can be safely cast to the base pointer type without applying any offset (which can only be true if the concrete value type only has one base class, and the base class is not virtual).
|
| Base * | getUnsafeLargeObjectBasePointer () |
| | Get a base pointer to the wrapped value, under the assumption that the value currently held by the wrapper does not fit into the small object optimization.
|
| const Base * | getUnsafeLargeObjectBasePointer () const |
| | Get a base pointer to the wrapped value, under the assumption that the value currently held by the wrapper does not fit into the small object optimization.
|
| auto & | operator* () |
| | Get a base reference to the wrapped value.
|
| const auto & | operator* () const |
| | Get a base reference to the wrapped value.
|
| Base * | operator-> () |
| | Get a base pointer to the wrapped value.
|
| const Base * | operator-> () const |
| | Get a base pointer to the wrapped value.
|
| template<typename T> |
| std::decay_t< T > * | get_if () noexcept |
| | Try to get a pointer to the wrapped value.
|
| template<typename T> |
| const std::decay_t< T > * | get_if () const noexcept |
| | Try to get a pointer to the wrapped value.
|
| template<typename T> |
| std::decay_t< T > & | get () |
| | Access the wrapped value.
|
| template<typename T> |
| const std::decay_t< T > & | get () const |
| | Access the wrapped value.
|
template<typename Base, std::size_t SmallCapacity = sizeof(void*) * 3, std::size_t SmallAlignment = alignof(void*)>
class grem::AnyBase< Base, SmallCapacity, SmallAlignment >
Generic type-erased semi-regular value wrapper.
- Template Parameters
-
| Base | generic base type, or void. |
| SmallCapacity | maximum capacity for small object optimization. |
| SmallAlignment | maximum alignment for small object optimization. |
template<typename Base, std::size_t SmallCapacity = sizeof(void*) * 3, std::size_t SmallAlignment = alignof(void*)>
template<typename T>
requires (!std::is_same_v<std::decay_t<T>, AnyBase>)
| grem::AnyBase< Base, SmallCapacity, SmallAlignment >::AnyBase |
( |
T && | value | ) |
|
|
inline |
Construct a wrapper from a value.
- Parameters
-
| value | value to forward to the stored value's constructor. |
- Exceptions
-
| any | exception thrown by the value type's constructor. |
| std::bad_alloc | on allocation failure, if the value type does not qualify for small object optimization. |
- Note
- The stored value's concrete type will be std::decay_t<T>.
template<typename Base, std::size_t SmallCapacity = sizeof(void*) * 3, std::size_t SmallAlignment = alignof(void*)>
template<typename T, typename... Args>
Create a wrapper of a new value.
- Template Parameters
-
| T | type of the concrete value to create. |
- Parameters
-
| args | arguments to forward to the constructor of the new value. |
- Returns
- a wrapper around the newly created value.
- Exceptions
-
| any | exception thrown by the value type's constructor. |
| std::bad_alloc | on allocation failure, if the value type does not qualify for small object optimization. |
- Note
- The stored value's concrete type will be std::decay_t<T>.
template<typename Base, std::size_t SmallCapacity = sizeof(void*) * 3, std::size_t SmallAlignment = alignof(void*)>
template<typename T, typename... Args>
| std::decay_t< T > & grem::AnyBase< Base, SmallCapacity, SmallAlignment >::emplace |
( |
Args &&... | args | ) |
|
|
inline |
Destroy the wrapped object if one exists, then replace it with a new object.
- Template Parameters
-
| T | type of the concrete value to create. |
- Parameters
-
| args | arguments to forward to the constructor of the new value. |
- Returns
- a reference to the newly created value.
- Exceptions
-
| any | exception thrown by the value type's constructor. |
| std::bad_alloc | on allocation failure, if the value type does not qualify for small object optimization. |
- Note
- The stored value's concrete type will be std::decay_t<T>.
template<typename Base, std::size_t SmallCapacity = sizeof(void*) * 3, std::size_t SmallAlignment = alignof(void*)>
| Base * grem::AnyBase< Base, SmallCapacity, SmallAlignment >::getUnsafeSmallObjectBasePointer |
( |
| ) |
|
|
inlinenodiscard |
Get a base pointer to the wrapped value, under the assumption that the value currently held by the wrapper fits into the small object optimization (in both size and alignment), and also that its address can be safely cast to the base pointer type without applying any offset (which can only be true if the concrete value type only has one base class, and the base class is not virtual).
- Returns
- a non-owning pointer to the value held by the wrapper.
- Warning
- Failure to meet the requirements described above results in undefined behavior.
- See also
- getUnsafeLargeObjectBasePointer()
template<typename Base, std::size_t SmallCapacity = sizeof(void*) * 3, std::size_t SmallAlignment = alignof(void*)>
| const Base * grem::AnyBase< Base, SmallCapacity, SmallAlignment >::getUnsafeSmallObjectBasePointer |
( |
| ) |
const |
|
inlinenodiscard |
Get a base pointer to the wrapped value, under the assumption that the value currently held by the wrapper fits into the small object optimization (in both size and alignment), and also that its address can be safely cast to the base pointer type without applying any offset (which can only be true if the concrete value type only has one base class, and the base class is not virtual).
- Returns
- a non-owning read-only pointer to the value held by the wrapper.
- Warning
- Failure to meet the requirements described above results in undefined behavior.
- See also
- getUnsafeLargeObjectBasePointer()