template <class T>
rll::optional<T&> class

Specialization for when T is a reference. optional<T&> acts similarly to a T*, but provides more operations and shows intent more clearly.

Public types

using value_type = T&

Constructors, destructors, conversion operators

operator bool() const explicit constexpr noexcept
optional() constexpr noexcept
Constructs an optional that does not contain a value.
optional(nullopt_t) constexpr noexcept
optional(optional const& rhs) defaulted noexcept
optional(optional&& rhs) defaulted
template <class U = T, detail::enable_if_t<! detail::is_optional<detail::decay_t<U>>::value>* = nullptr>
optional(U&& u) constexpr noexcept
Constructs the stored value with u.
template <class U>
optional(optional<U> const& rhs) explicit constexpr noexcept
~optional() defaulted
No-op.

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 U = T, detail::enable_if_t<! detail::is_optional<detail::decay_t<U>>::value>* = nullptr>
auto emplace(U&& u) →  optional& noexcept
Rebinds this optional to u.
auto has_value() const →  bool constexpr noexcept
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 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*() →  T& noexcept
Returns the stored value.
auto operator*() const →  T const& constexpr noexcept
auto operator->() const →  T const* constexpr noexcept
Returns a pointer to the stored value.
auto operator->() →  T* noexcept
auto operator=(nullopt_t) →  optional& noexcept
auto operator=(optional const& rhs) →  optional& defaulted
template <class U = T, detail::enable_if_t<! detail::is_optional<detail::decay_t<U>>::value>* = nullptr>
auto operator=(U&& u) →  optional&
Rebinds this optional to u.
template <class U>
auto operator=(optional<U> const& rhs) →  optional& noexcept
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&
template <class U>
auto value_or(U&& u) const & →  T constexpr noexcept
Returns the stored value if there is one, otherwise returns u
template <class U>
auto value_or(U&& u) && →  T noexcept
\group value_or

Function documentation

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

Copy constructor

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

template <class T>
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>
template <class F>
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 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.

Rebinds this optional to the referee of rhs if there is one. Otherwise resets the stored value in *this.

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

Converting copy assignment operator.

Rebinds this optional to the referee of rhs if there is one. Otherwise resets the stored value in *this.