|
Blender V5.3
|
#include <BLI_any_derived.hh>
Public Member Functions | |
| AnyDerived ()=default | |
| AnyDerived (const AnyDerived &other) | |
| AnyDerived (AnyDerived &&other) noexcept | |
| AnyDerived (Base *impl) | |
| AnyDerived (std::shared_ptr< Base > impl) | |
| AnyDerived & | operator= (const AnyDerived &other) |
| AnyDerived & | operator= (AnyDerived &&other) noexcept |
| template<typename ImplT, typename... Args> requires std::is_base_of_v<Base, ImplT> | |
| void | emplace (Args &&...args) |
| operator bool () const | |
| Base & | operator* () const |
| Base * | operator-> () const |
| Base * | get () const |
Protected Member Functions | |
| Base * | impl_from_storage () const |
This allows storing or passing around derived classes of a common base class. Typically, this always requires allocating the value on the heap and passing it around e.g. as unique_ptr. AnyDerived has small buffer optimization. So if the type is small, it can be stored directly without an additional allocation.
If all derived types are known where the type is used, it can be more efficient to use std::variant<Derived1, Derived2, ...> instead. AnyDerived uses type erasure through the use of Any and therefore works even when not all used derived types are known.
This is used extensively for virtual arrays. Each type of virtual array is implemented as subclass of VArrayImpl while VArray actually stores a specific implementation.
Note: If the value is not stored inline, it's currently stored as a shared_ptr which is shared when the AnyDerived is copied. This behavior is fine and efficient for all current uses but it may need to be generalized if AnyDerived is supposed to be used in more places.
Definition at line 70 of file BLI_any_derived.hh.
|
default |
Referenced by AnyDerived(), AnyDerived(), operator=(), and operator=().
|
inline |
Definition at line 88 of file BLI_any_derived.hh.
References AnyDerived(), and impl_from_storage().
|
inlinenoexcept |
Definition at line 93 of file BLI_any_derived.hh.
References AnyDerived(), and impl_from_storage().
|
inlineexplicit |
Definition at line 100 of file BLI_any_derived.hh.
|
inlineexplicit |
Definition at line 105 of file BLI_any_derived.hh.
References get().
|
inline |
Definition at line 136 of file BLI_any_derived.hh.
References emplace().
Referenced by emplace(), blender::tests::TEST(), blender::tests::TEST(), and blender::tests::TEST().
|
inline |
Definition at line 167 of file BLI_any_derived.hh.
Referenced by AnyDerived(), and blender::VArrayCommon< T >::get_implementation().
|
inlineprotected |
Definition at line 173 of file BLI_any_derived.hh.
Referenced by AnyDerived(), AnyDerived(), operator=(), and operator=().
|
inline |
Definition at line 152 of file BLI_any_derived.hh.
|
inline |
Definition at line 157 of file BLI_any_derived.hh.
|
inline |
Definition at line 162 of file BLI_any_derived.hh.
|
inlinenoexcept |
Definition at line 122 of file BLI_any_derived.hh.
References AnyDerived(), and impl_from_storage().
|
inline |
Definition at line 112 of file BLI_any_derived.hh.
References AnyDerived(), and impl_from_storage().