Honeycomb
0.1
Component-Model Framework
|
Enables any type to be optional so it can exist in an uninitialized null state. More...
#include <Optional.h>
Public Member Functions | |
optional () | |
Uninitialized by default. More... | |
optional (optnull_t) | |
optional (const optional &rhs) | |
optional (optional &rhs) | |
optional (optional &&rhs) | |
template<class U > | |
optional (const optional< U > &rhs) | |
template<class U > | |
optional (optional< U > &rhs) | |
template<class U > | |
optional (optional< U > &&rhs) | |
template<class U > | |
optional (U &&rhs) | |
~optional () | |
optional & | operator= (optnull_t) |
Reset the optional to an uninitialized state. More... | |
optional & | operator= (const optional &rhs) |
Assign wrapped object. More... | |
optional & | operator= (optional &rhs) |
optional & | operator= (optional &&rhs) |
template<class U > | |
optional & | operator= (const optional< U > &rhs) |
template<class U > | |
optional & | operator= (optional< U > &rhs) |
template<class U > | |
optional & | operator= (optional< U > &&rhs) |
template<class U > | |
optional & | operator= (U &&rhs) |
Assign object. On the first assignment the instance is copy/move constructed, assignments thereafter use copy/move assign. More... | |
bool | operator== (optnull_t) const |
bool | operator!= (optnull_t) const |
const T & | operator* () const |
T & | operator* () |
const T * | operator-> () const |
T * | operator-> () |
operator const T & () const | |
operator T & () | |
operator bool () const | |
Test whether optional is initialized. More... | |
operator bool () | |
const T & | get () const |
Get wrapped object. Optional must be initialized. More... | |
T & | get () |
const T * | ptr () const |
Get pointer to wrapped object. Returns null if not initialized. More... | |
T * | ptr () |
Friends | |
template<class T_ > | |
class | optional |
ostream & | operator<< (ostream &os, const optional &rhs) |
Enables any type to be optional so it can exist in an uninitialized null state.
An optional is large enough to hold an instance of its wrapped type. On construction or first assignment the instance is copy/move constructed, assignments thereafter use copy/move assign. Assigning to optnull
will reset the optional to an uninitialized state, destructing any instance.
Supports wrapped const/ref types.
Variables are commonly defined as pointers for the sole reason that pointers can exist in a null state. In this case, an optional can be used instead of a pointer to make the behavior explicit and encourage stack allocation. Optional syntax is also clearer for function calls:
func(iterator* optIter = nullptr); func(&iter) ----> func(optional<iterator> optIter = optnull); func(iter) func(int* retVal = nullptr); func(&retInt) ----> func(optional<int&> retVal = optnull); func(retInt)
Example:
|
inline |
Uninitialized by default.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Get wrapped object. Optional must be initialized.
|
inline |
|
inlineexplicit |
Test whether optional is initialized.
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Reset the optional to an uninitialized state.
|
inline |
Assign wrapped object.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Assign object. On the first assignment the instance is copy/move constructed, assignments thereafter use copy/move assign.
For an optional to be assignable to rhs
it must also be constructible with rhs
, this is necessary for allowing the optional to be nullable.
|
inline |
|
inline |
Get pointer to wrapped object. Returns null if not initialized.
|
inline |
|
friend |