|
Honeycomb
0.1
Android / iOS 3D Game Engine
|
Enables any type to be optional so it can exist in an uninitialized null state. More...
#include <Option.h>
Public Member Functions | |
| option () | |
| Uninitialized by default. More... | |
| option (optnull_t) | |
| option (const option &rhs) | |
| option (option &rhs) | |
| option (option &&rhs) | |
| template<class U > | |
| option (const option< U > &rhs) | |
| template<class U > | |
| option (option< U > &rhs) | |
| template<class U > | |
| option (option< U > &&rhs) | |
| template<class U > | |
| option (U &&rhs) | |
| ~option () | |
| option & | operator= (optnull_t) |
| Reset the option to an uninitialized state. More... | |
| option & | operator= (const option &rhs) |
| Assign wrapped object. More... | |
| option & | operator= (option &rhs) |
| option & | operator= (option &&rhs) |
| template<class U > | |
| option & | operator= (const option< U > &rhs) |
| template<class U > | |
| option & | operator= (option< U > &rhs) |
| template<class U > | |
| option & | operator= (option< U > &&rhs) |
| template<class U > | |
| option & | 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 option is initialized. More... | |
| operator bool () | |
| const T & | get () const |
| Get wrapped object. Option 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 | option |
| StringStream & | operator<< (StringStream &os, const option &rhs) |
| To string. More... | |
Enables any type to be optional so it can exist in an uninitialized null state.
An option 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 option 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 option can be used instead of a pointer to make the behavior explicit and encourage stack allocation. Option syntax is also clearer for function calls:
func(iterator* optIter = nullptr); func(&iter) ----> func(option<iterator> optIter = optnull); func(iter) func(int* retVal = nullptr); func(&retInt) ----> func(option<int&> retVal = optnull); func(retInt)
Example:
|
inline |
Uninitialized by default.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Get wrapped object. Option must be initialized.
|
inline |
|
inlineexplicit |
Test whether option is initialized.
|
inlineexplicit |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Reset the option 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 option to be assignable to rhs it must also be constructible with rhs, this is necessary for allowing the option to be nullable.
|
inline |
|
inline |
Get pointer to wrapped object. Returns null if not initialized.
|
inline |
|
friend |
To string.
1.8.3.1