The class template optional manages an optional contained value, i.e. a value that may or may not be present.
More...
|
| | optional (detail::enable_overload_if_t< std::is_copy_constructible< T >::value, const optional & > other) |
| | Copy constructs an optional. More...
|
| |
|
| optional (detail::disable_overload_if_t< std::is_copy_constructible< T >::value, const optional & > other)=delete |
| |
| | optional (detail::enable_overload_if_t< std::is_move_constructible< T >::value, optional && > other) |
| | Move constructs an optional. More...
|
| |
|
| optional (detail::disable_overload_if_t< std::is_move_constructible< T >::value, optional && > other)=delete |
| |
| template<typename... Args, typename = enable_if_t<std::is_constructible<T,Args...>::value>> |
| constexpr | optional (in_place_t, Args &&... args) |
| | Constructs an optional object that contains a value. More...
|
| |
| template<typename U , typename... Args, typename = enable_if_t<std::is_constructible<T, std::initializer_list<U>&, Args...>::value>> |
| constexpr | optional (in_place_t, std::initializer_list< U > ilist, Args &&...args) |
| | Constructs an optional object that contains a value. More...
|
| |
| optional & | operator= (nullopt_t) |
| | Assigns this optional to be a null optional. More...
|
| |
| optional & | operator= (detail::enable_overload_if_t< std::is_copy_constructible< T >::value &&std::is_copy_assignable< T >::value, const optional & > other) |
| | Copy assigns the optional stored in other. More...
|
| |
|
optional & | operator= (detail::disable_overload_if_t< std::is_copy_constructible< T >::value &&std::is_copy_assignable< T >::value, const optional & > other)=delete |
| |
| optional & | operator= (detail::enable_overload_if_t< std::is_move_constructible< T >::value &&std::is_move_assignable< T >::value, optional && > other) |
| | Move assigns the optional stored in other. More...
|
| |
|
optional & | operator= (detail::disable_overload_if_t< std::is_move_constructible< T >::value &&std::is_move_assignable< T >::value, optional && > other)=delete |
| |
| template<typename U = T, typename = enable_if_t<detail::optional_is_value_assignable<T,U>::value>> |
| optional & | operator= (U &&value) |
| | Perfect-forwarded assignment. More...
|
| |
| template<typename U > |
| optional & | operator= (enable_if_t< detail::optional_is_copy_convert_assignable< T, U >::value, const optional< U > & > other) |
| | Assigns the state of other. More...
|
| |
| template<typename U > |
| optional & | operator= (enable_if_t< detail::optional_is_move_convert_assignable< T, U >::value, optional< U > && > other) |
| | Assigns the state of other. More...
|
| |
| constexpr | operator bool () const noexcept |
| | Checks whether *this contains a value. More...
|
| |
| constexpr bool | has_value () const noexcept |
| | Checks whether *this contains a value. More...
|
| |
| void | swap (optional &other) |
| | Swaps the contents with those of other. More...
|
| |
| void | reset () noexcept(std::is_nothrow_destructible< T >::value) |
| | If *this contains a value, destroy that value as if by value().T::~T(). More...
|
| |
| template<typename... Args> |
| void | emplace (Args &&...args) |
| | Constructs the contained value in-place. More...
|
| |
| template<typename U , typename... Args> |
| void | emplace (std::initializer_list< U > ilist, Args &&...args) |
| | Constructs the contained value in-place. More...
|
| |
|
template<typename U , bpstd::enable_if_t< bpstd::detail::optional_is_copy_convertible< T, U >::value &&std::is_convertible< const U &, T >::value > * > |
| BPSTD_INLINE_VISIBILITY | optional (const optional< U > &other) |
| |
|
template<typename U , bpstd::enable_if_t< bpstd::detail::optional_is_move_convertible< T, U >::value &&std::is_convertible< U &&, T >::value > * > |
| BPSTD_INLINE_VISIBILITY | optional (optional< U > &&other) |
| |
|
template<typename... Args, typename > |
| constexpr BPSTD_INLINE_VISIBILITY | optional (in_place_t, Args &&...args) |
| |
|
template<typename U , typename... Args, typename > |
| constexpr BPSTD_INLINE_VISIBILITY | optional (in_place_t, std::initializer_list< U > ilist, Args &&...args) |
| |
|
template<typename U , bpstd::enable_if_t< bpstd::detail::optional_is_value_convertible< T, U >::value &&std::is_convertible< U &&, T >::value > * > |
| constexpr BPSTD_INLINE_VISIBILITY | optional (U &&value) |
| |
|
template<typename U , typename > |
| BPSTD_INLINE_VISIBILITY bpstd::optional< T > & | operator= (U &&value) |
| |
|
template<typename U > |
| constexpr BPSTD_INLINE_VISIBILITY bpstd::optional< T >::value_type | value_or (U &&default_value) const & |
| |
|
template<typename U > |
| BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR bpstd::optional< T >::value_type | value_or (U &&default_value) && |
| |
|
template<typename... Args> |
| BPSTD_INLINE_VISIBILITY void | emplace (Args &&...args) |
| |
|
template<typename U , typename... Args> |
| BPSTD_INLINE_VISIBILITY void | emplace (std::initializer_list< U > ilist, Args &&...args) |
| |
|
|
constexpr | optional () noexcept |
| | Constructs an optional that does not contain a value.
|
| |
|
constexpr | optional (nullopt_t) noexcept |
| | Constructs an optional that does not contain a value.
|
| |
|
| template<typename U , enable_if_t< detail::optional_is_copy_convertible< T, U >::value &&std::is_convertible< const U &, T >::value > * = nullptr> |
| | optional (const optional< U > &other) |
| | Converting copy constructor. More...
|
| |
| template<typename U , enable_if_t< detail::optional_is_copy_convertible< T, U >::value &&!std::is_convertible< const U &, T >::value > * = nullptr> |
| | optional (const optional< U > &other) |
| | Converting copy constructor. More...
|
| |
|
| template<typename U , enable_if_t< detail::optional_is_move_convertible< T, U >::value &&std::is_convertible< U &&, T >::value > * = nullptr> |
| | optional (optional< U > &&other) |
| | Converting move constructor. More...
|
| |
| template<typename U , enable_if_t< detail::optional_is_move_convertible< T, U >::value &&!std::is_convertible< U &&, T >::value > * = nullptr> |
| | optional (optional< U > &&other) |
| | Converting move constructor. More...
|
| |
|
| template<typename U = T, enable_if_t< detail::optional_is_value_convertible< T, U >::value &&std::is_convertible< U &&, T >::value > * = nullptr> |
| constexpr | optional (U &&value) |
| | Constructs an optional object that contains a value. More...
|
| |
| template<typename U = T, enable_if_t< detail::optional_is_value_convertible< T, U >::value &&!std::is_convertible< U &&, T >::value > * = nullptr> |
| constexpr | optional (U &&value) |
| | Constructs an optional object that contains a value. More...
|
| |
|
| BPSTD_CPP14_CONSTEXPR value_type * | operator-> () noexcept |
| | Accesses the contained value. More...
|
| |
| constexpr const value_type * | operator-> () const noexcept |
| | Accesses the contained value. More...
|
| |
|
| BPSTD_CPP14_CONSTEXPR value_type & | operator* () &noexcept |
| | Accesses the contained value. More...
|
| |
| BPSTD_CPP14_CONSTEXPR value_type && | operator* () &&noexcept |
| | Accesses the contained value. More...
|
| |
| constexpr const value_type & | operator* () const &noexcept |
| | Accesses the contained value. More...
|
| |
| constexpr const value_type && | operator* () const &&noexcept |
| | Accesses the contained value. More...
|
| |
|
| BPSTD_CPP14_CONSTEXPR value_type & | value () & |
| | Returns the contained value. More...
|
| |
| BPSTD_CPP14_CONSTEXPR value_type && | value () && |
| | Returns the contained value. More...
|
| |
|
| const BPSTD_CPP14_CONSTEXPR value_type & | value () const & |
| | Returns the contained value. More...
|
| |
| const BPSTD_CPP14_CONSTEXPR value_type && | value () const && |
| | Returns the contained value. More...
|
| |
|
| template<typename U > |
| constexpr value_type | value_or (U &&default_value) const & |
| | Returns the contained value if *this has a value, otherwise returns default_value. More...
|
| |
| template<typename U > |
| BPSTD_CPP14_CONSTEXPR value_type | value_or (U &&default_value) && |
| | Returns the contained value if *this has a value, otherwise returns default_value. More...
|
| |
template<typename T>
class bpstd::optional< T >
The class template optional manages an optional contained value, i.e. a value that may or may not be present.
A common use case for optional is the return value of a function that may fail. As opposed to other approaches, such as std::pair<T,bool>, optional handles expensive to construct objects well and is more readable, as the intent is expressed explicitly.
Any instance of optional<T> at any given point in time either contains a value or does not contain a value.
If an optional<T> contains a value, the value is guaranteed to be allocated as part of the optional object footprint, i.e. no dynamic memory allocation ever takes place. Thus, an optional object models an object, not a pointer, even though the operator*() and operator->() are defined.
When an object of type optional<T> is contextually converted to bool, the conversion returns true if the object contains a value and false if it does not contain a value.
The optional object contains a value in the following conditions:
- The object is initialized with a value of type T
- The object is assigned from another optional that contains a value.
- The object does not contain a value in the following conditions:
- The object is default-initialized.
- The object is initialized with a value of nullopt_t or an optional object that does not contain a value.
- The object is assigned from a value of nullopt_t or from an optional that does not contain a value
- Template Parameters
-
Definition at line 53 of file optional.hpp.