This class is a replacement for C++17 std::optional. More...
#include <cvb/shims/optional.hpp>
Public Member Functions | |
optional () noexcept | |
Default ctor not storing a value. | |
optional (nullopt_t) noexcept | |
Ctor for explicitly not storing a value. | |
template<class... ARGS> | |
optional (in_place_t, ARGS &&... args) | |
In-place constructs a new T object. More... | |
template<class U , typename std::enable_if< std::is_assignable< T &, U >::value, int >::type = 0> | |
optional (U &&value) | |
Ctor from an object assignable to T . More... | |
template<class U , typename std::enable_if< std::is_assignable< T &, U >::value, int >::type = 0> | |
optional & | operator= (U &&value) |
Assignment operator for an object assignable to T . More... | |
template<typename std::enable_if< std::is_copy_constructible< T >::value, int >::type = 0> | |
optional (const optional &rhs) | |
Copy ctor. More... | |
template<typename std::enable_if< std::is_copy_assignable< T >::value, int >::type = 0> | |
optional & | operator= (const optional &rhs) |
Copy operator. More... | |
template<typename std::enable_if< std::is_move_constructible< T >::value, int >::type = 0> | |
optional (optional &&rhs) | |
Move ctor. More... | |
template<typename std::enable_if< std::is_move_assignable< T >::value, int >::type = 0> | |
optional & | operator= (optional &&rhs) |
Move operator. More... | |
~optional () | |
Dtor. | |
const T * | operator-> () const noexcept |
Gets the reference to the stored object. More... | |
T * | operator-> () noexcept |
Gets the reference to the stored object. More... | |
const T & | operator* () const noexcept |
Gets the reference to the stored object. More... | |
T & | operator* () noexcept |
Gets the reference to the stored object. More... | |
operator bool () const noexcept | |
Gets whether this optional contains a value. More... | |
template<class... ARGS> | |
T & | emplace (ARGS &&... args) |
Constructs a new T in-place. More... | |
bool | has_value () const noexcept |
Gets whether this optional contains a value. More... | |
void | reset () |
Destroys any contained value. | |
void | swap (optional &other) |
Swaps this object with the other object. More... | |
const T & | value () const |
Gets the contained value. More... | |
T & | value () |
Gets the contained value. More... | |
template<class U , typename std::enable_if< std::is_assignable< T &, U >::value, int >::type = 0> | |
T | value_or (U &&default_value) const |
Gets the contained value if has_value() is true; default_value otherwise. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
optional< typename std::decay< T >::type > | make_optional (T &&value) |
Factory function to create an optional from a T object. More... | |
template<class T , class... ARGS> | |
optional< T > | make_optional (ARGS &&... args) |
Factory function to in-place construct a T in an optional. More... | |
This class is a replacement for C++17 std::optional.
|
inline |
In-place constructs a new T
object.
ARGS | Type list of all arguments to be forwarded to T . |
[in] | args | Arguments that are forwarded to the ctor of |
|
inline |
Ctor from an object assignable to T
.
U | Type assignable to T . |
[in] | value | Value to store. |
|
inline |
Constructs a new T
in-place.
If a this object has_value() is true, the old value is destroyed via its destructor.
ARGS | Type list of all arguments to be forwarded to T . |
[in] | args | Command line arguments forwarded to the ctor of T . |
|
inlinenoexcept |
Gets whether this optional contains a value.
|
inlineexplicitnoexcept |
Gets whether this optional contains a value.
|
inlinenoexcept |
Gets the reference to the stored object.
|
inlinenoexcept |
Gets the reference to the stored object.
|
inlinenoexcept |
Gets the reference to the stored object.
|
inlinenoexcept |
Gets the reference to the stored object.
Copy operator.
[in] | rhs | Object to copy. |
Move operator.
[in] | rhs | Object to copy. |
|
inline |
Assignment operator for an object assignable to T
.
U | Type assignable to T . |
[in] | value | Value to store. |
|
inline |
Swaps this object with the other object.
The contents of this and the other are swapped.
[in] | other | Optional to swap value with. |
|
inline |
Gets the contained value.
bad_optional_access | thrown if has_value() is false. |
|
inline |
Gets the contained value.
bad_optional_access | thrown if has_value() is false. |
|
inline |
Gets the contained value if has_value() is true; default_value otherwise.
|
related |
Factory function to in-place construct a T
in an optional.
T | Type of value to store. |
ARGS | Type list of all arguments to be forwarded to T . |
[in] | args | Arguments to be forwarded to the ctor of T . |
T
.
|
related |
Factory function to create an optional from a T
object.
T | Type of value to store. |
[in] | value | Value to be forwarded to the optional. |