siplasplas
A library for C++ reflection and introspection
|
Implements a type-erased value container with minimal value semantics requirements. More...
#include <siplasplas/typeerasure/simpleany.hpp>
Classes | |
struct | EmptyTag |
Type used to represent empty state. More... | |
Public Member Functions | |
SimpleAny () | |
Constructs an empty SimpleAny. | |
SimpleAny (const cpp::typeerasure::TypeInfo &typeInfo) | |
Default constructs a value of the given type. More... | |
bool | empty () const |
Checks whether the any has an object hosted in or if is empty. More... | |
template<typename T , typename = std::enable_if_t< !std::is_base_of< SimpleAny, std::decay_t<T> >::value >> | |
SimpleAny (const T &value) | |
Constructs an any of type T from an lvalue of type T. More... | |
template<typename OtherStorage > | |
SimpleAny (const SimpleAny< OtherStorage > &other) | |
template<typename OtherStorage > | |
SimpleAny (SimpleAny< OtherStorage > &&other) | |
SimpleAny (const SimpleAny &other) | |
SimpleAny (SimpleAny &&other) | |
template<typename T > | |
bool | hasType () const |
Checks if the any has a value of type T. More... | |
template<typename T > | |
const std::decay_t< T > & | get () const |
Returns a readonly reference to the hosted object. More... | |
template<typename T > | |
std::decay_t< T > & | get () |
Returns a reference to the hosted object. More... | |
cpp::typeerasure::TypeInfo | typeInfo () const |
Returns the type information of the hosted type. | |
cpp::SimpleAny< cpp::NonOwningStorage > | getReference () |
Returns a reference any to the hosted object. | |
cpp::SimpleAny< cpp::ConstNonOwningStorage > | getReference () const |
Returns a const reference any to the hosted object. | |
template<typename T > | |
SimpleAny & | operator= (const T &value) |
Assigns a value of type T. More... | |
SimpleAny & | operator= (const SimpleAny &other) |
SimpleAny & | operator= (SimpleAny &&other) |
const Storage & | getStorage () const |
Returns the storage backend of the SimpleAny object. | |
Static Public Member Functions | |
template<typename T , typename... Args> | |
static SimpleAny | create (Args &&...args) |
Constructs a SimpleAny with an in-place constructed value of type T. More... | |
Implements a type-erased value container with minimal value semantics requirements.
The template SimpleAny implements a type-erased value container, that is, a type that can hold values of different types at runtime.
SimpleAny assumes that types hosted on it satisfy the CopyConstructible, MoveConstructible, CopyAssignable, MoveAssignable, and Destructible. If any of those concepts are not satisfied, an exception would be thrown if the corresponding feature is used. This means you can use non-satisfying types as long as the operation is not needed (Invoked). For example:
Note this behavior is undefined and may be disabled in release builds. In general, using semantics not supporeted by the hosted type has undefined behavior.
Storage | Storage policy. See any storage |
|
inline |
Default constructs a value of the given type.
The behavior is undefined if the given type is not default constructible
typeInfo | Type of the value |
|
inline |
Constructs an any of type T from an lvalue of type T.
A copy is done from the T lvalue argument to the any storage
value | A value of type T to store in the any |
|
inlinestatic |
Constructs a SimpleAny with an in-place constructed value of type T.
The value is constructed directly on the any storage, no extra copy operations are done. Arguments are passed as-is to the object constructor.
T | Type of the value to be constructed. |
args | Constructor arguments |
|
inline |
Checks whether the any has an object hosted in or if is empty.
|
inline |
Returns a readonly reference to the hosted object.
T | Type of the returned object. If T is different from the hosted object type, the behavior is undefined (See hasType()). |
|
inline |
Returns a reference to the hosted object.
T | Type of the returned object. If T is different from the hosted object type, the behavior is undefined (See hasType()). |
|
inline |
Checks if the any has a value of type T.
|
inline |
Assigns a value of type T.
If the current hosted type is T, performs a copy assignment of value
into the hosted object. Else, the destructor of the hosted object is invoked and the value is copy-constructed into the storage.
value | Value to be assigned to the any |
*this