SPH
|
Wrapper of type value of which may or may not be present. More...
#include <Optional.h>
Public Member Functions | |
Optional ()=default | |
Creates an uninitialized value. More... | |
template<typename T , typename = std::enable_if_t<std::is_copy_assignable<T>::value>> | |
Optional (const T &t) | |
Copy constuctor from stored value. More... | |
Optional (Type &&t) | |
Move constuctor from stored value. More... | |
Optional (const Optional &other) | |
Copy constructor from other optional. More... | |
Optional (Optional &&other) | |
Move constructor from other optional. More... | |
Optional (const NothingType &) | |
Construct uninitialized value. More... | |
~Optional () | |
template<typename... TArgs> | |
void | emplace (TArgs &&... args) |
Constructs the uninitialized object from a list of arguments. More... | |
template<typename T , typename = std::enable_if_t<std::is_assignable<Type, T>::value>> | |
Optional & | operator= (const T &t) |
Copies the value on right-hand side, initializing the optional if necessary. More... | |
Optional & | operator= (Type &&t) |
Moves the value on right-hand side, initializing the optional if necessary. More... | |
Optional & | operator= (const Optional &other) |
Copies the value of another optional object. More... | |
Optional & | operator= (Optional &&other) |
Moves the value of another optional object. More... | |
Optional & | operator= (const NothingType &) |
Destroys the stored value, provided the object has been initialized. More... | |
INLINE Type & | value () |
Returns the reference to the stored value. More... | |
INLINE const Type & | value () const |
Returns the const reference to the stored value. More... | |
template<typename TOther > | |
INLINE Type | valueOr (const TOther &other) const |
Returns the stored value if the object has been initialized, otherwise returns provided parameter. More... | |
template<typename TException , typename... TArgs> | |
INLINE Type | valueOrThrow (TArgs &&... args) |
Returns the stored value if the object has been initialized, otherwise throws an exception, constructed with the provided list of arguments. More... | |
INLINE const RawType * | operator-> () const |
Used to access members of the stored value. More... | |
INLINE RawType * | operator-> () |
Used to access members of the stored value. More... | |
INLINE | operator bool () const |
Checks if the object has been initialized. More... | |
INLINE bool | operator! () const |
Returns true if the object is uninitialized. More... | |
Wrapper of type value of which may or may not be present.
Similar to std::optional introduced in c++17. See http://en.cppreference.com/w/cpp/utility/optional
Definition at line 23 of file Optional.h.
|
inline |
Copy constuctor from stored value.
Initializes the optional value.
Definition at line 46 of file Optional.h.
Move constuctor from stored value.
Initializes the optional value.
Definition at line 54 of file Optional.h.
Copy constructor from other optional.
Copies the state and if the passed optional is initialized, copies the value as well.
Definition at line 63 of file Optional.h.
Move constructor from other optional.
Copies the state and if the passed optional is initialized, copies the value as well. Also un-initializes moved optional.
Definition at line 74 of file Optional.h.
|
inline |
Construct uninitialized value.
Definition at line 83 of file Optional.h.
Definition at line 87 of file Optional.h.
|
inline |
Constructs the uninitialized object from a list of arguments.
If the object was previously initialized, the stored value is destroyed.
Definition at line 95 of file Optional.h.
Checks if the object has been initialized.
Definition at line 224 of file Optional.h.
Returns true if the object is uninitialized.
Definition at line 229 of file Optional.h.
Used to access members of the stored value.
The value must be initialized.
Definition at line 218 of file Optional.h.
Used to access members of the stored value.
The value must be initialized.
Definition at line 210 of file Optional.h.
|
inline |
Destroys the stored value, provided the object has been initialized.
Definition at line 161 of file Optional.h.
|
inline |
Copies the value of another optional object.
If the right-hand side object was previously uninitialized, the value in this object is destroyed.
Definition at line 129 of file Optional.h.
|
inline |
Copies the value on right-hand side, initializing the optional if necessary.
Definition at line 105 of file Optional.h.
Moves the value of another optional object.
If the right-hand side object was previously uninitialized, the value in this object is destroyed.
Definition at line 146 of file Optional.h.
Moves the value on right-hand side, initializing the optional if necessary.
Definition at line 116 of file Optional.h.
Returns the reference to the stored value.
Object must be already initialized.
Definition at line 172 of file Optional.h.
Returns the const reference to the stored value.
Object must be already initialized.
Definition at line 180 of file Optional.h.
|
inline |
Returns the stored value if the object has been initialized, otherwise returns provided parameter.
Definition at line 188 of file Optional.h.
|
inline |
Returns the stored value if the object has been initialized, otherwise throws an exception, constructed with the provided list of arguments.
Definition at line 199 of file Optional.h.