Template Class optional< T & >
Defined in File tl-optional.hpp
Class Documentation
-
template<class T>
class optional<T&> Specialization for when
T
is a reference.optional<T&>
acts similarly to aT*
, but provides more operations and shows intent more clearly.Public Functions
- template<class F> inline TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t< F, T & > and_then (F &&f) &
Carries out some operation which returns an optional on the stored object if there is one.
- template<class F> inline TL_OPTIONAL_11_CONSTEXPR detail::invoke_result_t< F, T & > and_then (F &&f) &&
-
template<class F>
inline constexpr detail::invoke_result_t<F, const T&> and_then(F &&f) const &
-
template<class F>
inline constexpr detail::invoke_result_t<F, const T&> and_then(F &&f) const &&
- template<class F, detail::enable_if_ret_void< F > * = nullptr> inline optional< T > TL_OPTIONAL_11_CONSTEXPR or_else (F &&f) &
Calls
f
if the optional is empty.
- template<class F, detail::disable_if_ret_void< F > * = nullptr> inline optional< T > TL_OPTIONAL_11_CONSTEXPR or_else (F &&f) &
- template<class F, detail::disable_if_ret_void< F > * = nullptr> inline optional< T > TL_OPTIONAL_11_CONSTEXPR or_else (F &&f) &&
-
template<class F, detail::enable_if_ret_void<F>* = nullptr>
inline optional<T> or_else(F &&f) const &
- template<class F, detail::disable_if_ret_void< F > * = nullptr> inline optional< T > TL_OPTIONAL_11_CONSTEXPR or_else (F &&f) const &
-
template<class F, detail::enable_if_ret_void<F>* = nullptr>
inline optional<T> or_else(F &&f) const &&
-
template<class F, detail::disable_if_ret_void<F>* = nullptr>
inline optional<T> or_else(F &&f) const &&
-
template<class F, class U>
inline U map_or(F &&f, U &&u) & Maps the stored value with
f
if there is one, otherwise returnsu
-
template<class F, class U>
inline detail::invoke_result_t<U> map_or_else(F &&f, U &&u) & Maps the stored value with
f
if there is one, otherwise callsu
and returns the result.
-
template<class F, class U>
inline detail::invoke_result_t<U> map_or_else(F &&f, U &&u) &&
-
template<class F, class U>
inline detail::invoke_result_t<U> map_or_else(F &&f, U &&u) const &
-
template<class F, class U>
inline detail::invoke_result_t<U> map_or_else(F &&f, U &&u) const &&
-
template<class U>
inline constexpr optional<typename std::decay<U>::type> conjunction(U &&u) const Returns
u
if*this
has a value, otherwise an empty optional.
- inline TL_OPTIONAL_11_CONSTEXPR optional disjunction (const optional &rhs) &
Returns
rhs
if*this
is empty, otherwise the current value.
- inline TL_OPTIONAL_11_CONSTEXPR optional disjunction (const optional &rhs) &&
- inline TL_OPTIONAL_11_CONSTEXPR optional disjunction (optional &&rhs) &
- inline TL_OPTIONAL_11_CONSTEXPR optional disjunction (optional &&rhs) &&
-
inline constexpr optional() noexcept
Constructs an optional that does not contain a value.
-
TL_OPTIONAL_11_CONSTEXPR optional(const optional &rhs) noexcept = default
Copy constructor
If
rhs
contains a value, the stored value is direct-initialized with it. Otherwise, the constructed optional is empty.
-
TL_OPTIONAL_11_CONSTEXPR optional(optional &&rhs) = default
Move constructor
If
rhs
contains a value, the stored value is direct-initialized with it. Otherwise, the constructed optional is empty.
-
template<class U = T, detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value>* = nullptr>
inline constexpr optional(U &&u) noexcept Constructs the stored value with
u
.
-
~optional() = default
No-op.
-
inline optional &operator=(nullopt_t) noexcept
Assignment to empty.
Destroys the current value if there is one.
-
optional &operator=(const optional &rhs) = default
Copy assignment.
Rebinds this optional to the referee of
rhs
if there is one. Otherwise resets the stored value in*this
.
-
template<class U = T, detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value>* = nullptr>
inline optional &operator=(U &&u) Rebinds this optional to
u
.
-
template<class U>
inline optional &operator=(const optional<U> &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
.
-
template<class U = T, detail::enable_if_t<!detail::is_optional<detail::decay_t<U>>::value>* = nullptr>
inline optional &emplace(U &&u) noexcept Rebinds this optional to
u
.
- inline TL_OPTIONAL_11_CONSTEXPR T * operator-> () noexcept
- inline TL_OPTIONAL_11_CONSTEXPR T & operator* () noexcept
Returns the stored value.
-
inline constexpr bool has_value() const noexcept
-
inline explicit constexpr operator bool() const noexcept
- inline TL_OPTIONAL_11_CONSTEXPR T & value ()
Returns the contained value if there is one, otherwise throws bad_optional_access
- inline TL_OPTIONAL_11_CONSTEXPR const T & value () const
-
template<class U>
inline constexpr T value_or(U &&u) const & noexcept Returns the stored value if there is one, otherwise returns
u
- template<class U> inline TL_OPTIONAL_11_CONSTEXPR T value_or (U &&u) &&noexcept
\group value_or
-
inline void reset() noexcept
Destroys the stored value if one exists, making the optional empty.
Public Members
- template<class F> TL_OPTIONAL_11_CONSTEXPR decltype(detail::optional_map_impl(std::declval< optional & >(), std::declval< F && >())) map (F &&f) &
Carries out some operation on the stored object if there is one.
- template<class F> TL_OPTIONAL_11_CONSTEXPR decltype(detail::optional_map_impl(std::declval< optional && >(), std::declval< F && >())) map (F &&f) &&
-
template<class F>
constexpr decltype(detail::optional_map_impl(std::declval<const optional&>(), std::declval<F&&>())) map(F &&f) const &
-
template<class F>
constexpr decltype(detail::optional_map_impl(std::declval<const optional&&>(), std::declval<F&&>())) map(F &&f) const &&
- template<class F> TL_OPTIONAL_11_CONSTEXPR decltype(detail::optional_map_impl(std::declval< optional & >(), std::declval< F && >())) transform (F &&f) &
Carries out some operation on the stored object if there is one.
- template<class F> TL_OPTIONAL_11_CONSTEXPR decltype(detail::optional_map_impl(std::declval< optional && >(), std::declval< F && >())) transform (F &&f) &&
\group map \synopsis template <class F> auto transform(F &&f) &&;