A simplistic but type-safe and RAII compliant storage for anything. Enclosed data is owned by this type.
More...
|
| template<typename T > |
| | FAny (T *newObject, TAnyTypeFacilities< T > const &facilities={}) |
| |
| FORCEINLINE | FAny () |
| |
| | FAny (FAny const &other) |
| |
| | FAny (FAny &&other) |
| |
| | ~FAny () |
| |
| template<typename T > |
| const T * | TryGet () const |
| |
| template<typename T > |
| T * | TryGet () |
| |
| template<typename T , typename Self > |
| decltype(auto) | WithAlias (this Self &&self) |
| | Specify one type the enclosed value can be safely cast to, and is valid to be used with TryGet.
|
| |
| template<typename Self , typename... T> |
| decltype(auto) | With (this Self &&self, TTypes< T... > &&) |
| | Specify multiple types the enclosed value can be safely cast to, and are valid to be used with TryGet.
|
| |
| FORCEINLINE bool | IsValid () const |
| |
| FORCEINLINE FType | GetType () const |
| |
| FORCEINLINE TSet< FType > const & | GetValidTypes () const |
| |
A simplistic but type-safe and RAII compliant storage for anything. Enclosed data is owned by this type.
Use this with care, the underlying data can be only accessed with the same type as it has been constructed with, or with types provided by ValidAs. This means derived classes cannot be accessed with their base types safely and implicitly. MCRO however provides methods for classes to allow them exposing base types to FAny (and other facilities):
class FMyThing :
public TInherit<IFoo, IBar, IEtc>
{
}
Inherit via this template to allow other API to reflect upon the base types of deriving class....
TInherit has a member alias using Bases = TTypes<...> and that can be used by FAny to automatically register base classes as compatible ones.
Enclosed value is recommended to be copy constructible. It may yield a runtime error otherwise. Moving an FAny will just transfer ownership of the wrapped object but will not move construct a new object. The source FAny will be reset to an invalid state.
- Todo
- C++ 26 has promising proposal for static value-based reflection, which can gather metadata from classes or even emit them. The best summary I found so far is a stack-overflow answer https://stackoverflow.com/a/77477029 Once that's available we can gather base classes in compile time, and do dynamic casting of objects without the need for intrusive extra syntax, or extra work at construction. Currently GCC's
__bases would be perfect for the job, but other popular compilers don't have similar intrinsics. Once such a feature becomes widely available base classes can be automatically added as aliases for types wrapped in FAny.
Definition at line 92 of file Any.h.