Range-v3 Range algorithms, views, and actions for the Standard Library |

Public Types | Public Member Functions | List of all members
ranges::optional< T > Struct Template Reference

## Public Types
using | value_type = meta::_t< std::remove_cv< T > >

## Public Member Functions
template<typename... Args>
T & | emplace (Args &&... args) noexcept(std::is_nothrow_constructible< T, Args... >::value)
template<typename E , typename... Args>
T & | emplace (std::initializer_list< E > il, Args &&... args) noexcept(std::is_nothrow_constructible< T, std::initializer_list< E > &, Args... >::value)
template<typename U >
| explicit (!convertible_to< U const &, T >) optional(optional< U > const &that)
template<typename U = T>
constexpr | explicit (!convertible_to< U, T >) optional(U &&v)
constexpr | operator bool () const noexcept
constexpr optional & | operator= (nullopt_t) noexcept
optional & | operator= (optional &&)=default
optional & | operator= (optional const &)=default
template<typename U >
constexpr optional & | operator= (optional< U > &&that)
template<typename U >
constexpr optional & | operator= (optional< U > const &that)
template<typename U = T>
constexpr optional & | operator= (U &&u) noexcept(std::is_nothrow_constructible< T, U >::value &&std::is_nothrow_assignable< T &, U >::value)
template<typename E , typename... Args>
constexpr | optional (in_place_t, std::initializer_list< E > il, Args &&... args) noexcept(std::is_nothrow_constructible< T, std::initializer_list< E > &, Args... >::value)
constexpr | optional (nullopt_t) noexcept
| optional (optional &&)=default
| optional (optional const &)=default
template<typename U >
| optional (optional< U > &&that)
template<typename U >
| optional (optional< U > &&that)
constexpr T & | value () &
constexpr T && | value () &&
constexpr T const & | value () const &
constexpr T const && | value () const &&
template<typename U >
constexpr T | value_or (U &&u) &&
template<typename U >
constexpr T | value_or (U &&u) const &

## Member Function Documentation

## ◆ emplace() [1/2]

template<typename T >
template<typename... Args>

T& ranges::optional< T >::emplace | ( | Args &&... | args | ) |
| noexcept

Precondition
  requires `constructible_from<T, Args...>`

## ◆ emplace() [2/2]

template<typename T >
template<typename E , typename... Args>

T& ranges::optional< T >::emplace | ( | std::initializer_list< E > | il,
|  | Args &&... | args
| ) |  |
| noexcept

Precondition
  requires `constructible_from<T, std::initializer_list<E> &, Args...>`

## ◆ explicit() [1/2]

template<typename T >
template<typename U >

ranges::optional< T >::explicit | ( | !convertible_to< U const &, T > |  | ) | const &

Precondition
  requires `optional_should_convert<U, T> && constructible_from<T, U const &>`

## ◆ explicit() [2/2]

template<typename T >
template<typename U = T>

constexpr ranges::optional< T >::explicit | ( | !convertible_to< U, T > |  | ) | &&
| constexpr

Precondition
  requires `(!same_as<detail::decay_t<U>, in_place_t>) && (!same_as<detail::decay_t<U>, optional>) && constructible_from<T, U>`

## ◆ operator=() [1/3]

template<typename T >
template<typename U >

constexpr optional& ranges::optional< T >::operator= | ( | optional< U > && | that | ) |
| constexpr

Precondition
  requires `optional_should_convert_assign<U, T> && constructible_from<T, U> && assignable_from<T &, U>`

## ◆ operator=() [2/3]

template<typename T >
template<typename U >

constexpr optional& ranges::optional< T >::operator= | ( | optional< U > const & | that | ) |
| constexpr

Precondition
  requires `optional_should_convert_assign<U, T> && constructible_from<T, const U &> && assignable_from<T &, const U &>`

## ◆ operator=() [3/3]

template<typename T >
template<typename U = T>

constexpr optional& ranges::optional< T >::operator= | ( | U && | u | ) |
| constexpr noexcept

Precondition
  requires `(!same_as<optional, detail::decay_t<U>>) && (!(satisfies<T, std::is_scalar> && same_as<T, detail::decay_t<U>>)) && constructible_from<T, U> && assignable_from<T &, U>`

## ◆ value_or() [1/2]

template<typename T >
template<typename U >

constexpr T ranges::optional< T >::value_or | ( | U && | u | ) | &&
| constexpr

Precondition
  requires `move_constructible<T> && convertible_to<U, T>`

## ◆ value_or() [2/2]

template<typename T >
template<typename U >

constexpr T ranges::optional< T >::value_or | ( | U && | u | ) | const &
| constexpr

Precondition
  requires `copy_constructible<T> && convertible_to<U, T>`

## Constructor & Destructor Documentation

## ◆ optional() [1/3]

template<typename T >
template<typename E , typename... Args>

constexpr ranges::optional< T >::optional | ( | in_place_t | ,
|  | std::initializer_list< E > | il,
|  | Args &&... | args
| ) |  |
| explicit constexpr noexcept

Precondition
  requires `constructible_from<T, std::initializer_list<E> &, Args...>`

## ◆ optional() [2/3]

template<typename T >
template<typename U >

ranges::optional< T >::optional | ( | optional< U > && | that | ) |

Precondition
  requires `optional_should_convert<U, T> && constructible_from<T, U> && convertible_to<U, T>`

## ◆ optional() [3/3]

template<typename T >
template<typename U >

ranges::optional< T >::optional | ( | optional< U > && | that | ) |
| explicit

Precondition
  requires `optional_should_convert<U, T> && constructible_from<T, U> && (!convertible_to<U, T>)` //