A class that holds instances of any type that is copy-constructible.
Example:
#include <framework/YiAny.h>
Public Member Functions | |
CYIAny () | |
template<typename T , std::enable_if_t<!std::is_same< std::decay_t< T >, CYIAny >::value > * = nullptr> | |
CYIAny (T &&value) | |
CYIAny (const CYIAny &other) | |
CYIAny (CYIAny &&other) noexcept | |
~CYIAny () | |
CYIAny & | Swap (CYIAny &other) |
CYIAny & | operator= (const CYIAny &other) |
CYIAny & | operator= (CYIAny &&other) |
template<typename T , std::enable_if_t<!std::is_same< std::decay_t< T >, CYIAny >::value > * = nullptr> | |
CYIAny & | operator= (T &&value) |
bool | Empty () const |
void | Clear () |
template<typename T > | |
bool | ContainsType () const |
bool | MatchesType (const CYIAny &other) const |
template<typename T > | |
std::decay_t< T > & | Get () |
template<typename T > | |
const std::decay_t< T > & | Get () const |
Static Public Member Functions | |
template<typename T > | |
static size_t | GetRequiredHeapMemory () |
Friends | |
class | CYIAnyTest |
CYIAny::CYIAny | ( | ) |
Initializes the CYIAny as empty.
CYIAny::CYIAny | ( | T && | value | ) |
Initializes the CYIAny by copying or moving the passed value, stored as the template type.
CYIAny::CYIAny | ( | const CYIAny & | other | ) |
|
noexcept |
CYIAny::~CYIAny | ( | ) |
void CYIAny::Clear | ( | ) |
bool CYIAny::ContainsType | ( | ) | const |
Returns true if the CYIAny contains a value of exactly the given template type, if the given template type is a const and/or reference type of exactly the type contained by the CYIAny.
A return value of true means a Get() to the given type is safe.
The template parameter cannot be CYIAny. Const and reference qualifiers are stripped away.
Compatible types are not supported. This will return false even if the given template type is a base class of the contained type. This will also return false even if the given template type is an integer type that differs only in size or signedness from the contained type.
bool CYIAny::Empty | ( | ) | const |
std::decay_t<T>& CYIAny::Get | ( | ) |
Gets a reference to the contained value. The given template type must exactly match the type of the contained value, excluding const and reference qualifiers.
The returned reference is invalidated if the CYIAny is modified other than through the returned reference.
The template parameter cannot CYIAny.
Example:
const std::decay_t<T>& CYIAny::Get | ( | ) | const |
Gets a const reference to the contained value. The given template type must exactly match the type of the contained value, excluding const and reference qualifiers.
The returned reference is invalidated if the CYIAny is modified.
The template parameter cannot CYIAny.
|
static |
Returns the total amount of heap memory needed to store type T in a CYIAny instance. This does not include allocation overheads (such as metadata), and does not include heap allocations performed internally by type T. Returns 0 if the type T can be stored in a CYIAny instance without any heap allocations.
For example, calling GetRequiredHeapMemory<int>()
will return 0
, and calling GetRequiredHeapMemory<glm::mat4>
will return sizeof(glm::mat4)
.
bool CYIAny::MatchesType | ( | const CYIAny & | other | ) | const |
Returns true if this CYIAny contains a value of exactly the same type as the given CYIAny.
Also returns true if both this CYIAny and the given CYIAny are empty.
Compatible types are not supported. This will return false even if the type of one CYIAny is a base class of the other. This will also return false even if the types are integers that differ only in size or signedness.
CYIAny& CYIAny::operator= | ( | T && | value | ) |
|
friend |