|
| constexpr | Optional () noexcept |
| | Construct an empty optional.
|
| constexpr | Optional (Nullopt value) noexcept |
| | Construct an empty optional.
|
template<typename... Args>
requires (std::is_constructible_v<T, Args...>) |
| constexpr | Optional (std::in_place_t tag, Args &&... args) |
| | Construct an optional with an active value in-place.
|
template<typename U, typename... Args>
requires (std::is_constructible_v<T, std::initializer_list<U>&, Args...>) |
| constexpr | Optional (std::in_place_t tag, std::initializer_list< U > ilist, Args &&... args) |
| | Construct an optional with an active value in-place, with an initializer list as the first constructor argument.
|
template<typename U = std::remove_cv_t<T>>
requires (!std::is_same_v<std::remove_cvref_t<U>, std::in_place_t> && !std::is_same_v<std::remove_cvref_t<U>, Optional> && (!std::is_same_v<std::remove_cv_t<T>, bool> || !template_specialization_of<std::remove_cvref_t<U>, Optional>) && std::is_constructible_v<T, U &&> && std::is_convertible_v<U &&, T>) |
| constexpr | Optional (U &&value) |
| | Implicit converting constructor.
|
template<typename U = std::remove_cv_t<T>>
requires (!std::is_same_v<std::remove_cvref_t<U>, std::in_place_t> && !std::is_same_v<std::remove_cvref_t<U>, Optional> && (!std::is_same_v<std::remove_cv_t<T>, bool> || !template_specialization_of<std::remove_cvref_t<U>, Optional>) && std::is_constructible_v<T, U &&> && !std::is_convertible_v<U &&, T>) |
| constexpr | Optional (U &&value) |
| | Explicit converting constructor.
|
| constexpr | ~Optional ()=default |
| | Destructor.
|
| constexpr | Optional (const Optional &other)=default |
| | Copy constructor.
|
| constexpr | Optional (Optional &&other) noexcept(std::is_nothrow_move_constructible_v< T >)=default |
| | Move constructor.
|
template<typename U>
requires ((std::is_same_v<std::remove_cv_t<T>, bool> || (!std::is_constructible_v<T, Optional<U>&> && !std::is_constructible_v<T, const Optional<U>&> && !std::is_constructible_v<T, Optional<U> &&> && !std::is_constructible_v<T, const Optional<U> &&> && !std::is_convertible_v<Optional<U>&, T> && !std::is_convertible_v<const Optional<U>&, T> && !std::is_convertible_v<Optional<U> &&, T> && !std::is_convertible_v<const Optional<U> &&, T>)) && std::is_constructible_v<T, const U&> && std::is_convertible_v<const U&, T>) |
| constexpr | Optional (const Optional< U > &other) |
| | Implicit converting copy constructor.
|
template<typename U>
requires ((std::is_same_v<std::remove_cv_t<T>, bool> || (!std::is_constructible_v<T, Optional<U>&> && !std::is_constructible_v<T, const Optional<U>&> && !std::is_constructible_v<T, Optional<U> &&> && !std::is_constructible_v<T, const Optional<U> &&> && !std::is_convertible_v<Optional<U>&, T> && !std::is_convertible_v<const Optional<U>&, T> && !std::is_convertible_v<Optional<U> &&, T> && !std::is_convertible_v<const Optional<U> &&, T>)) && std::is_constructible_v<T, const U&> && !std::is_convertible_v<const U&, T>) |
| constexpr | Optional (const Optional< U > &other) |
| | Explicit converting copy constructor.
|
template<typename U>
requires ((std::is_same_v<std::remove_cv_t<T>, bool> || (!std::is_constructible_v<T, Optional<U>&> && !std::is_constructible_v<T, const Optional<U>&> && !std::is_constructible_v<T, Optional<U> &&> && !std::is_constructible_v<T, const Optional<U> &&> && !std::is_convertible_v<Optional<U>&, T> && !std::is_convertible_v<const Optional<U>&, T> && !std::is_convertible_v<Optional<U> &&, T> && !std::is_convertible_v<const Optional<U> &&, T>)) && std::is_constructible_v<T, U &&> && std::is_convertible_v<U &&, T>) |
| constexpr | Optional (Optional< U > &&other) |
| | Implicit converting move constructor.
|
template<typename U>
requires ((std::is_same_v<std::remove_cv_t<T>, bool> || (!std::is_constructible_v<T, Optional<U>&> && !std::is_constructible_v<T, const Optional<U>&> && !std::is_constructible_v<T, Optional<U> &&> && !std::is_constructible_v<T, const Optional<U> &&> && !std::is_convertible_v<Optional<U>&, T> && !std::is_convertible_v<const Optional<U>&, T> && !std::is_convertible_v<Optional<U> &&, T> && !std::is_convertible_v<const Optional<U> &&, T>)) && std::is_constructible_v<T, U &&> && !std::is_convertible_v<U &&, T>) |
| constexpr | Optional (Optional< U > &&other) |
| | Explicit converting move constructor.
|
| constexpr Optional & | operator= (Nullopt) noexcept |
| | Destroy the underlying value if present and reset the optional to an empty state.
|
template<typename U = std::remove_cv_t<T>>
requires (!std::is_same_v<std::remove_cvref_t<U>, Optional> && std::is_constructible_v<T, U> && std::is_assignable_v<T&, U> && (!std::is_scalar_v<T> || !std::is_same_v<T, std::decay_t<U>>)) |
| constexpr Optional & | operator= (U &&value) |
| | Converting assignment.
|
| constexpr Optional & | operator= (const Optional &other)=default |
| | Copy assignment.
|
| constexpr Optional & | operator= (Optional &&other) noexcept(std::is_nothrow_move_constructible_v< T > &&//NOLINT(cppcoreguidelines-noexcept-move-operations, performance-noexcept-move-constructor) std::is_nothrow_move_assignable_v< T >)=default |
| | Move assignment.
|
template<typename U>
requires (std::is_constructible_v<T, const U&> && std::is_assignable_v<T&, const U&> && !std::is_constructible_v<T, Optional<U>&> && !std::is_constructible_v<T, const Optional<U>&> && !std::is_constructible_v<T, Optional<U> &&> && !std::is_constructible_v<T, const Optional<U> &&> && !std::is_convertible_v<Optional<U>&, T> && !std::is_convertible_v<const Optional<U>&, T> && !std::is_convertible_v<Optional<U> &&, T> && !std::is_convertible_v<const Optional<U> &&, T> && !std::is_assignable_v<T&, Optional<U>&> && !std::is_assignable_v<T&, const Optional<U>&> && !std::is_assignable_v<T&, Optional<U> &&> && !std::is_assignable_v<T&, const Optional<U> &&>) |
| constexpr Optional & | operator= (const Optional< U > &other) |
| | Converting copy assignment.
|
template<typename U>
requires (std::is_constructible_v<T, U> && std::is_assignable_v<T&, U> && !std::is_constructible_v<T, Optional<U>&> && !std::is_constructible_v<T, const Optional<U>&> && !std::is_constructible_v<T, Optional<U> &&> && !std::is_constructible_v<T, const Optional<U> &&> && !std::is_convertible_v<Optional<U>&, T> && !std::is_convertible_v<const Optional<U>&, T> && !std::is_convertible_v<Optional<U> &&, T> && !std::is_convertible_v<const Optional<U> &&, T> && !std::is_assignable_v<T&, Optional<U>&> && !std::is_assignable_v<T&, const Optional<U>&> && !std::is_assignable_v<T&, Optional<U> &&> && !std::is_assignable_v<T&, const Optional<U> &&>) |
| constexpr Optional & | operator= (Optional< U > &&other) |
| | Converting move assignment.
|
| constexpr const T * | operator-> () const noexcept |
| | Access the underlying value by pointer without a safety check.
|
| constexpr T * | operator-> () noexcept |
| | Access the underlying value by pointer without a safety check.
|
| constexpr const T & | operator* () const &noexcept |
| | Access the underlying value without a safety check.
|
| constexpr T & | operator* () &noexcept |
| | Access the underlying value without a safety check.
|
| constexpr const T && | operator* () const &&noexcept |
| | Access the underlying value without a safety check.
|
| constexpr T && | operator* () &&noexcept |
| | Access the underlying value without a safety check.
|
| constexpr | operator bool () const noexcept |
| | Check if the optional contains a value.
|
| constexpr bool | has_value () const noexcept |
| | Check if the optional contains a value.
|
| constexpr T & | value () & |
| | Access the underlying value.
|
| constexpr const T & | value () const & |
| | Access the underlying value.
|
| constexpr T && | value () && |
| | Access the underlying value.
|
| constexpr const T && | value () const && |
| | Access the underlying value.
|
| template<typename U> |
| constexpr T | value_or (U &&defaultValue) const & |
| | Get the underlying value, or a fallback value in case the optional is empty.
|
| template<typename U> |
| constexpr T | value_or (U &&defaultValue) && |
| | Get the underlying value, or a fallback value in case the optional is empty.
|
| template<typename F> |
| constexpr auto | and_then (F &&f) & |
| | Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.
|
| template<typename F> |
| constexpr auto | and_then (F &&f) const & |
| | Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.
|
| template<typename F> |
| constexpr auto | and_then (F &&f) && |
| | Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.
|
| template<typename F> |
| constexpr auto | and_then (F &&f) const && |
| | Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.
|
| template<typename F> |
| constexpr auto | transform (F &&f) & |
| | Invoke a function with the underlying value, or return an empty optional in case the optional is empty.
|
| template<typename F> |
| constexpr auto | transform (F &&f) const & |
| | Invoke a function with the underlying value, or return an empty optional in case the optional is empty.
|
| template<typename F> |
| constexpr auto | transform (F &&f) && |
| | Invoke a function with the underlying value, or return an empty optional in case the optional is empty.
|
| template<typename F> |
| constexpr auto | transform (F &&f) const && |
| | Invoke a function with the underlying value, or return an empty optional in case the optional is empty.
|
| template<typename F> |
| constexpr Optional | or_else (F &&f) const & |
| | Get an optional containing the underlying value, or the result of a function in case the optional is empty.
|
| template<typename F> |
| constexpr Optional | or_else (F &&f) && |
| | Get an optional containing the underlying value, or the result of a function in case the optional is empty.
|
| constexpr void | swap (Optional &other) noexcept(std::is_nothrow_move_constructible_v< T > &&std::is_nothrow_swappable_v< T >) |
| | Swap this optional's value with that of another.
|
| constexpr void | reset () noexcept |
| | Destroy the underlying value if present and reset the optional to an empty state.
|
template<typename... Args>
requires (std::is_constructible_v<T, Args...>) |
| constexpr T & | emplace (Args &&... args) |
| | Construct a new underlying value, destroying the old value if present.
|
template<typename U, typename... Args>
requires (std::is_constructible_v<T, std::initializer_list<U>&, Args...>) |
| constexpr T & | emplace (std::initializer_list< U > ilist, Args &&... args) |
| | Construct a new underlying value, with an initializer list as the first constructor argument, destroying the old value if present.
|
template<typename T>
class grem::Optional< T >
Optional value type that holds either a value or no value.
Its API mimics that of std::optional, including some functions added in C++23.
- Template Parameters
-
| T | type of the value that can be held by the optional. |