template <class T>
rll::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
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 = T, detail::enable_if_t<std::is_convertible<U && , T>::value>* = nullptr, detail::enable_forward_value<T, U>* = nullptr>
optional(U&& u) constexpr
Constructs the stored value with u.
template <class U, detail::enable_from_other<T, U, U const&>* = nullptr, detail::enable_if_t<std::is_convertible<U const&, T>::value>* = nullptr>
optional(optional<U> const& rhs)
Converting copy constructor.
template <class U, detail::enable_from_other<T, U, U && >* = nullptr, detail::enable_if_t<std::is_convertible<U && , T>::value>* = nullptr>
optional(optional<U>&& rhs)
Converting move constructor.
~optional() defaulted
Destroys the stored value if there is one.

Public functions

template <class F>
auto and_then(F&& f) & →  TL_OPTIONAL_11_CONSTEXPR auto
template <class F>
auto and_then(F&& f) && →  TL_OPTIONAL_11_CONSTEXPR 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) & →  TL_OPTIONAL_11_CONSTEXPR optional
Returns rhs if *this is empty, otherwise the current value.
auto disjunction(optional const& rhs) const & →  optional constexpr
auto disjunction(optional const& rhs) && →  TL_OPTIONAL_11_CONSTEXPR optional
auto disjunction(optional const& rhs) const && →  optional constexpr
auto disjunction(optional&& rhs) & →  TL_OPTIONAL_11_CONSTEXPR optional
auto disjunction(optional&& rhs) const & →  optional constexpr
auto disjunction(optional&& rhs) && →  TL_OPTIONAL_11_CONSTEXPR 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) & →  TL_OPTIONAL_11_CONSTEXPR auto
Carries out some operation on the stored object if there is one.
template <class F>
auto map(F&& f) && →  TL_OPTIONAL_11_CONSTEXPR 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 returns u.
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*() & →  TL_OPTIONAL_11_CONSTEXPR T&
Returns the stored value.
auto operator*() const & →  T const& constexpr
auto operator*() && →  TL_OPTIONAL_11_CONSTEXPR T&&
auto operator*() const && →  T const&& constexpr
auto operator->() const →  T const* constexpr
Returns a pointer to the stored value.
auto operator->() →  TL_OPTIONAL_11_CONSTEXPR 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&
auto optional(optional const& rhs) →  TL_OPTIONAL_11_CONSTEXPR defaulted
auto optional(optional&& rhs) →  TL_OPTIONAL_11_CONSTEXPR defaulted
template <class U, class... Args>
auto 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) →  TL_OPTIONAL_11_CONSTEXPR explicit
template <class F, detail::enable_if_ret_void<F>* = nullptr>
auto or_else(F&& f) & →  optional<T> TL_OPTIONAL_11_CONSTEXPR
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::disable_if_ret_void<F>* = nullptr>
auto or_else(F&& f) && →  optional<T> TL_OPTIONAL_11_CONSTEXPR
template <class F, detail::enable_if_ret_void<F>* = nullptr>
auto or_else(F&& f) const & →  optional<T>
template <class F, detail::disable_if_ret_void<F>* = nullptr>
auto or_else(F&& f) const & →  optional<T> TL_OPTIONAL_11_CONSTEXPR
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) & →  TL_OPTIONAL_11_CONSTEXPR auto
Carries out some operation on the stored object if there is one.
template <class F>
auto transform(F&& f) && →  TL_OPTIONAL_11_CONSTEXPR auto
template <class F>
auto transform(F&& f) const & →  auto constexpr
template <class F>
auto transform(F&& f) const && →  auto constexpr
auto value() & →  TL_OPTIONAL_11_CONSTEXPR T&
Returns the contained value if there is one, otherwise throws bad_optional_access.
auto value() const & →  TL_OPTIONAL_11_CONSTEXPR const T&
auto value() && →  TL_OPTIONAL_11_CONSTEXPR T&&
auto value() const && →  TL_OPTIONAL_11_CONSTEXPR 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) && →  TL_OPTIONAL_11_CONSTEXPR T

Function documentation

template <class T>
template <class F>
TL_OPTIONAL_11_CONSTEXPR auto rll::optional::and_then(F&& 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)

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) &

Maps the stored value with f if there is one, otherwise calls u and returns the result.

template <class T>
optional& rll::optional::operator=(nullopt_t) noexcept

Assignment to empty.

Destroys the current value if there is one.

template <class T>
optional& rll::optional::operator=(optional const& rhs) defaulted

Copy assignment.

Copies the value from rhs if there is one. Otherwise resets the stored value in *this.

template <class T>
optional& rll::optional::operator=(optional&& rhs) defaulted

Move assignment.

Moves the value from rhs if there is one. Otherwise resets the stored value in *this.

template <class T>
template <class U = T, detail::enable_assign_forward<T, U>* = nullptr>
optional& rll::optional::operator=(U&& u)

Assigns the stored value from u, destroying the old value if there was one.

template <class T>
template <class U, detail::enable_assign_from_other<T, U, U const&>* = nullptr>
optional& rll::optional::operator=(optional<U> const& rhs)

Converting copy assignment operator.

Copies the value from rhs if there is one. Otherwise resets the stored value in *this.

template <class T>
template <class U, detail::enable_assign_from_other<T, U, U>* = nullptr>
optional& rll::optional::operator=(optional<U>&& rhs)

Converting move assignment operator.

Moves the value from rhs if there is one. Otherwise resets the stored value in *this.

template <class T>
TL_OPTIONAL_11_CONSTEXPR rll::optional::optional(optional const& rhs) defaulted

Copy constructor

If rhs contains a value, the stored value is direct-initialized with it. Otherwise, the constructed optional is empty.

template <class T>
TL_OPTIONAL_11_CONSTEXPR rll::optional::optional(optional&& rhs) defaulted

Move constructor

If rhs contains a value, the stored value is direct-initialized with it. Otherwise, the constructed optional is empty.

template <class T>
void rll::optional::swap(optional& rhs) noexcept(…)

Swaps this optional with the other.

If neither optionals have a value, nothing happens. If both have a value, the values are swapped. If one has a value, it is moved to the other and the movee is left valueless.