#include <rll/optional.h>
template <class T>
optional class
An optional object is an object that contains the storage for another object and manages the lifetime of this contained object, if any. The contained object may be initialized after the optional object has been initialized, and may be destroyed before the optional object has been destroyed. The initialization state of the contained object is tracked by the optional object.
Public types
- using value_type = T
Constructors, destructors, conversion operators
- operator bool() const explicit constexpr noexcept
- optional() defaulted constexpr noexcept
- Constructs an optional that does not contain a value.
-
optional(nullopt_
t) constexpr noexcept - optional(optional const& rhs) defaulted
- optional(optional&& rhs) defaulted
-
template <class... Args>optional(detail::enable_if_t<std::
is_constructible<T, Args...>:: value, std:: in_place_t>, Args && ... args) explicit constexpr - Constructs the stored value in-place using the given arguments.
-
template <class U, class... Args>optional(detail::enable_if_t<std::
is_constructible<T, std:: initializer_list<U>&, Args && ...>:: value, std:: in_place_t>, std:: initializer_list<U> il, Args && ... args) explicit -
template <class U = T, detail::enable_if_t<std::optional(U&& u) constexpr
is_convertible<U && , T>:: value>* = nullptr, detail::enable_forward_value<T, U>* = nullptr> - Constructs the stored value with
u
. -
template <class U, detail::enable_from_other<T, U, U const&>* = nullptr, detail::enable_if_t<std::optional(optional<U> const& rhs)
is_convertible<U const&, T>:: value>* = nullptr> - Converting copy constructor.
-
template <class U, detail::enable_from_other<T, U, U && >* = nullptr, detail::enable_if_t<std::optional(optional<U>&& rhs)
is_convertible<U && , T>:: value>* = nullptr> - Converting move constructor.
- ~optional() defaulted
- Destroys the stored value if there is one.
Public functions
-
template <class F>auto and_then(F&& f) & → auto
-
template <class F>auto and_then(F&& f) && → auto
-
template <class F>auto and_then(F&& f) const & → auto constexpr
-
template <class F>auto and_then(F&& f) const && → auto constexpr
-
template <class U>auto conjunction(U&& u) const → optional<typename std::
decay<U>::type> constexpr - Returns
u
if*this
has a value, otherwise an empty optional. - auto disjunction(optional const& rhs) & → optional
- Returns
rhs
if*this
is empty, otherwise the current value. - auto disjunction(optional const& rhs) const & → optional constexpr
- auto disjunction(optional const& rhs) && → optional
- auto disjunction(optional const& rhs) const && → optional constexpr
- auto disjunction(optional&& rhs) & → optional
- auto disjunction(optional&& rhs) const & → optional constexpr
- auto disjunction(optional&& rhs) && → optional
- auto disjunction(optional&& rhs) const && → optional constexpr
-
template <class... Args>auto emplace(Args && ... args) → T&
-
template <class U, class... Args>auto emplace(std::
initializer_list<U> il, Args && ... args) → detail::enable_if_t<std:: is_constructible<T, std:: initializer_list<U>&, Args && ...>:: value, T&> - auto has_value() const → bool constexpr noexcept
- Returns whether or not the optional has a value.
-
template <class F>auto map(F&& f) & → auto
- Carries out some operation on the stored object if there is one.
-
template <class F>auto map(F&& f) && → auto
-
template <class F>auto map(F&& f) const & → auto constexpr
-
template <class F>auto map(F&& f) const && → auto constexpr
-
template <class F, class U>auto map_or(F&& f, U&& u) & → U
- Maps the stored value with
f
if there is one, otherwise returnsu
. -
template <class F, class U>auto map_or(F&& f, U&& u) && → U
-
template <class F, class U>auto map_or(F&& f, U&& u) const & → U
-
template <class F, class U>auto map_or(F&& f, U&& u) const && → U
-
template <class F, class U>auto map_or_else(F&& f, U&& u) & → detail::invoke_result_t<U>
-
template <class F, class U>auto map_or_else(F&& f, U&& u) && → detail::invoke_result_t<U>
-
template <class F, class U>auto map_or_else(F&& f, U&& u) const & → detail::invoke_result_t<U>
-
template <class F, class U>auto map_or_else(F&& f, U&& u) const && → detail::invoke_result_t<U>
- auto operator*() & → T&
- Returns the stored value.
- auto operator*() const & → T const& constexpr
- auto operator*() && → T&&
- auto operator*() const && → T const&& constexpr
- auto operator->() const → T const* constexpr
- Returns a pointer to the stored value.
- auto operator->() → T*
-
auto operator=(nullopt_
t) → optional& noexcept - auto operator=(optional const& rhs) → optional& defaulted
- auto operator=(optional&& rhs) → optional& defaulted
-
template <class U = T, detail::enable_assign_forward<T, U>* = nullptr>auto operator=(U&& u) → optional&
-
template <class U, detail::enable_assign_from_other<T, U, U const&>* = nullptr>auto operator=(optional<U> const& rhs) → optional&
-
template <class U, detail::enable_assign_from_other<T, U, U>* = nullptr>auto operator=(optional<U>&& rhs) → optional&
-
template <class F, detail::enable_if_ret_void<F>* = nullptr>auto or_else(F&& f) & → optional<T>
- Calls
f
if the optional is empty. -
template <class F, detail::enable_if_ret_void<F>* = nullptr>auto or_else(F&& f) && → optional<T>
-
template <class F, detail::enable_if_ret_void<F>* = nullptr>auto or_else(F&& f) const & → optional<T>
-
template <class F, detail::enable_if_ret_void<F>* = nullptr>auto or_else(F&& f) const && → optional<T>
- void reset() noexcept
- Destroys the stored value if one exists, making the optional empty.
- void swap(optional& rhs) noexcept(…)
- auto take() → optional
- Takes the value out of the optional, leaving it empty.
-
template <class F>auto transform(F&& f) & → auto
- Carries out some operation on the stored object if there is one.
-
template <class F>auto transform(F&& f) && → auto
-
template <class F>auto transform(F&& f) const & → auto constexpr
-
template <class F>auto transform(F&& f) const && → auto constexpr
- auto value() & → T&
- Returns the contained value if there is one, otherwise throws bad_
optional_ access. - auto value() const & → const T&
- auto value() && → T&&
- auto value() const && → const T&&
-
template <class U>auto value_or(U&& u) const & → T constexpr
- Returns the stored value if there is one, otherwise returns
u
-
template <class U>auto value_or(U&& u) && → T
Function documentation
template <class T>
template <class F>
auto rll::optional::and_then(F&& f) &
template <class F>
Carries out some operation which returns an optional on the stored object if there is one.
template <class T>
template <class... Args>
T& rll::optional::emplace(Args && ... args)
template <class... Args>
Constructs the value in-place, destroying the current one if there is one.
template <class T>
template <class F, class U>
detail::invoke_result_t<U> rll::optional::map_or_else(F&& f,
U&& u) &
template <class F, class U>
Maps the stored value with f
if there is one, otherwise calls u
and returns the result.