Mirror reflection library 0.5.13
|
A type erasure similar to Boost.Any with optional reference semantics. More...
#include <mirror/utils/some_type.hpp>
Public Member Functions | |
some (void) | |
Constructs an empty standalone instance without any value. | |
template<typename T > | |
some (T value, std::false_type=std::false_type()) | |
Constructs a new instance containing the passed value . | |
template<typename T > | |
some (T &inst, std::true_type by_ptr) | |
Constructs a new instance referring to the passed inst . | |
template<typename T > | |
some (const T &inst, std::true_type by_ptr) | |
Constructs a new instance referring to the passed inst . | |
bool | empty (void) const |
Tests if this instance of some is empty. | |
bool | standalone (void) const |
Tests if this instance is standalone or it refers to something. | |
some & | detach (void) |
Function that detaches this from the external instace by doing a copy. | |
bool | is_const (void) const |
Returns true if the the value referred-to by this instance is const. | |
bool | is_reference (void) const |
Returns true if this is a non-constant reference to an external value. | |
bool | is_value (void) const |
Returns true if this owns its value or refers to a const instance. | |
template<typename T > | |
bool | is (void) const |
Testing if this stores or refers to a value of a certain type. | |
template<typename T > | |
T | as (const some &s) const |
Function for getting the stored or referred-to value. | |
Friends | |
template<typename T > | |
T or T & | some_cast (some &s) |
Operator for casting to the stored type. | |
template<typename T > | |
T | some_cast (const some &s) |
Operator for casting to the stored type. |
A type erasure similar to Boost.Any with optional reference semantics.
The some class is a type erasure which can store values or references to values of other types. The instances of some
can be either standalone in cases when they contain the value, or they can refer to external instances. In case an instance of some
refers to another instance, this instance must be kept alive during the lifetime of the type erased some
instance or it must be detached before the lifetime of the instance referred-to ends.
mirror::some::some | ( | void | ) | [inline] |
Constructs an empty standalone instance without any value.
The some_cast and as function must not be called on empty instances of some
.
mirror::some::some | ( | T | value, |
std::false_type | = std::false_type() |
||
) | [inline] |
Constructs a new instance containing the passed value
.
This constructor creates a new standalone instance which contains the value
passed as parameter.
mirror::some::some | ( | T & | inst, |
std::true_type | by_ptr | ||
) | [inline] |
Constructs a new instance referring to the passed inst
.
This constructor creates a new instance attached (referring) to the value referred to by the inst
reference. The instance referred-to must be kept alive the whole time the newly constructed instance of some
is used or this instance must be detached
from the instance it refers to.
mirror::some::some | ( | const T & | inst, |
std::true_type | by_ptr | ||
) | [inline] |
Constructs a new instance referring to the passed inst
.
This constructor creates a new instance attached (referring) to the value referred-to by the inst
reference. The instance referred-to must be kept alive the whole time the newly constructed instance of some
is used or this instance must be detached
from the instance it refers to.
T mirror::some::as | ( | const some & | s | ) | const |
Function for getting the stored or referred-to value.
This member function can be use to get read-only access to the value stored inside or refered-to by this instance of some
. You don't need to use the const
specifier on the template parameter in contrast to the some_cast operator.
some& mirror::some::detach | ( | void | ) | [inline] |
Function that detaches this from the external instace by doing a copy.
If this instance is not standalone, then the detach
member function will make a copy of the external instance referred-to by this instance and store the copy. If this instance already is standalone then detach does not do anything.
bool mirror::some::empty | ( | void | ) | const |
bool mirror::some::is | ( | void | ) | const [inline] |
bool mirror::some::is_const | ( | void | ) | const [inline] |
bool mirror::some::is_reference | ( | void | ) | const [inline] |
Returns true if this is a non-constant reference to an external value.
This function can be used for testing if this instance of refers to some non-const external instance which can be modified via this. If this owns its value or it refers to a const value it returns false.
bool mirror::some::is_value | ( | void | ) | const [inline] |
Returns true if this owns its value or refers to a const instance.
This function can be used for testing if this instance owns its value or it refers to an external instance via a const reference. If this member function returns true, then it is necessary to test for constness with the is_const
member function before requesting non-const access (for assignement, calling non-const member functions, etc). If only read-only access is desired then the some_cast should be used with const
type or the as
member function should be used.
bool mirror::some::standalone | ( | void | ) | const [inline] |
Tests if this instance is standalone or it refers to something.
If this instance of some
contains and owns its value then standalone returns true otherwise, if it refers to an external instance it returns false. Instances which are not standalone can be made standalone by calling the detach
member function. This member function is the right one to test if this refers to something, since is_value
and is_reference
member functions are for other purposes.
T or T& some_cast | ( | some & | s | ) | [friend] |
Operator for casting to the stored type.
This function can be use to get read-only or read-write access to the value stored inside or refered to by this instance of some
. To get read-only access use const
Type
as the template parameter to get read-write reference to the value use a non-const type. Before trying to get access for writing test for constness with the is_const
member function.
T some_cast | ( | const some & | s | ) | [friend] |