GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::Optional< T > Class Template Reference

Optional value type that holds either a value or no value. More...

#include <GREM/core/data/Optional.hpp>

Public Member Functions

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.

Friends

constexpr void swap (Optional &a, Optional &b) noexcept(noexcept(a.swap(b)))
 Swap the values of two optionals.

Detailed Description

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
Ttype of the value that can be held by the optional.

Constructor & Destructor Documentation

◆ Optional() [1/12]

template<typename T>
grem::Optional< T >::Optional ( )
inlineconstexprnoexcept

Construct an empty optional.

◆ Optional() [2/12]

template<typename T>
grem::Optional< T >::Optional ( Nullopt value)
inlineconstexprnoexcept

Construct an empty optional.

Parameters
valueunit value representing an empty optional.

◆ Optional() [3/12]

template<typename T>
template<typename... Args>
requires (std::is_constructible_v<T, Args...>)
grem::Optional< T >::Optional ( std::in_place_t tag,
Args &&... args )
inlineexplicitconstexpr

Construct an optional with an active value in-place.

Parameters
tagstd::in_place, marking that this constructor should be used instead of the copy/move constructor.
argsarguments to pass to the underlying value's constructor.
Exceptions
anyexception thrown by the underlying value's constructor.

◆ Optional() [4/12]

template<typename T>
template<typename U, typename... Args>
requires (std::is_constructible_v<T, std::initializer_list<U>&, Args...>)
grem::Optional< T >::Optional ( std::in_place_t tag,
std::initializer_list< U > ilist,
Args &&... args )
inlineconstexpr

Construct an optional with an active value in-place, with an initializer list as the first constructor argument.

Parameters
tagstd::in_place, marking that this constructor should be used instead of the copy/move constructor.
ilistfirst argument to pass to the underlying value's constructor.
argssubsequent arguments to pass to the underlying value's constructor.
Exceptions
anyexception thrown by the underlying value's constructor.

◆ Optional() [5/12]

template<typename T>
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>)
grem::Optional< T >::Optional ( U && value)
inlineconstexpr

Implicit converting constructor.

Parameters
valueunderlying value to construct the optional from. Must be convertible to the underlying value type.
Exceptions
anyexception thrown by the underlying value's constructor.

◆ Optional() [6/12]

template<typename T>
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>)
grem::Optional< T >::Optional ( U && value)
inlineexplicitconstexpr

Explicit converting constructor.

Parameters
valueunderlying value to construct the optional from. Must be convertible to the underlying value type.
Exceptions
anyexception thrown by the underlying value's constructor.

◆ ~Optional()

template<typename T>
grem::Optional< T >::~Optional ( )
constexprdefault

Destructor.

◆ Optional() [7/12]

template<typename T>
grem::Optional< T >::Optional ( const Optional< T > & other)
constexprdefault

Copy constructor.

◆ Optional() [8/12]

template<typename T>
grem::Optional< T >::Optional ( Optional< T > && other) const
constexprdefaultnoexcept

Move constructor.

◆ Optional() [9/12]

template<typename T>
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>)
grem::Optional< T >::Optional ( const Optional< U > & other)
inlineconstexpr

Implicit converting copy constructor.

◆ Optional() [10/12]

template<typename T>
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>)
grem::Optional< T >::Optional ( const Optional< U > & other)
inlineexplicitconstexpr

Explicit converting copy constructor.

◆ Optional() [11/12]

template<typename T>
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>)
grem::Optional< T >::Optional ( Optional< U > && other)
inlineconstexpr

Implicit converting move constructor.

◆ Optional() [12/12]

template<typename T>
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>)
grem::Optional< T >::Optional ( Optional< U > && other)
inlineexplicitconstexpr

Explicit converting move constructor.

Member Function Documentation

◆ operator=() [1/6]

template<typename T>
Optional & grem::Optional< T >::operator= ( Nullopt )
inlineconstexprnoexcept

Destroy the underlying value if present and reset the optional to an empty state.

◆ operator=() [2/6]

template<typename T>
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>>))
Optional & grem::Optional< T >::operator= ( U && value)
inlineconstexpr

Converting assignment.

Parameters
valueunderlying value to construct the new value from. Must be convertible to the underlying value type.
Exceptions
anyexception thrown by the underlying constructor or assignment of the underlying value.

◆ operator=() [3/6]

template<typename T>
Optional & grem::Optional< T >::operator= ( const Optional< T > & other)
constexprdefault

Copy assignment.

◆ operator=() [4/6]

template<typename T>
Optional & grem::Optional< T >::operator= ( Optional< T > && other) const &&
constexprdefaultnoexcept

Move assignment.

◆ operator=() [5/6]

template<typename T>
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> &&>)
Optional & grem::Optional< T >::operator= ( const Optional< U > & other)
inlineconstexpr

Converting copy assignment.

◆ operator=() [6/6]

template<typename T>
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> &&>)
Optional & grem::Optional< T >::operator= ( Optional< U > && other)
inlineconstexpr

Converting move assignment.

◆ operator->() [1/2]

template<typename T>
const T * grem::Optional< T >::operator-> ( ) const
inlinenodiscardconstexprnoexcept

Access the underlying value by pointer without a safety check.

Returns
a non-owning read-only pointer to the underlying value.
Warning
If the optional is empty, the behavior is undefined.

◆ operator->() [2/2]

template<typename T>
T * grem::Optional< T >::operator-> ( )
inlinenodiscardconstexprnoexcept

Access the underlying value by pointer without a safety check.

Returns
a non-owning pointer to the underlying value.
Warning
If the optional is empty, the behavior is undefined.

◆ operator*() [1/4]

template<typename T>
const T & grem::Optional< T >::operator* ( ) const &
inlinenodiscardconstexprnoexcept

Access the underlying value without a safety check.

Returns
a read-only reference to the underlying value.
Warning
If the optional is empty, the behavior is undefined.

◆ operator*() [2/4]

template<typename T>
T & grem::Optional< T >::operator* ( ) &
inlinenodiscardconstexprnoexcept

Access the underlying value without a safety check.

Returns
a reference to the underlying value.
Warning
If the optional is empty, the behavior is undefined.

◆ operator*() [3/4]

template<typename T>
const T && grem::Optional< T >::operator* ( ) const &&
inlinenodiscardconstexprnoexcept

Access the underlying value without a safety check.

Returns
a read-only rvalue reference to the underlying value.
Warning
If the optional is empty, the behavior is undefined.

◆ operator*() [4/4]

template<typename T>
T && grem::Optional< T >::operator* ( ) &&
inlinenodiscardconstexprnoexcept

Access the underlying value without a safety check.

Returns
an rvalue reference to the underlying value.
Warning
If the optional is empty, the behavior is undefined.

◆ operator bool()

template<typename T>
grem::Optional< T >::operator bool ( ) const
inlineexplicitconstexprnoexcept

Check if the optional contains a value.

Returns
true if the optional contains a value, false if the optional is empty.

◆ has_value()

template<typename T>
bool grem::Optional< T >::has_value ( ) const
inlinenodiscardconstexprnoexcept

Check if the optional contains a value.

Returns
true if the optional contains a value, false if the optional is empty.

◆ value() [1/4]

template<typename T>
T & grem::Optional< T >::value ( ) &
inlinenodiscardconstexpr

Access the underlying value.

Returns
a reference to the underlying value.
Exceptions
BadOptionalAccessif the optional is empty.

◆ value() [2/4]

template<typename T>
const T & grem::Optional< T >::value ( ) const &
inlinenodiscardconstexpr

Access the underlying value.

Returns
a read-only reference to the underlying value.
Exceptions
BadOptionalAccessif the optional is empty.

◆ value() [3/4]

template<typename T>
T && grem::Optional< T >::value ( ) &&
inlinenodiscardconstexpr

Access the underlying value.

Returns
an rvalue reference to the underlying value.
Exceptions
BadOptionalAccessif the optional is empty.

◆ value() [4/4]

template<typename T>
const T && grem::Optional< T >::value ( ) const &&
inlinenodiscardconstexpr

Access the underlying value.

Returns
a read-only rvalue reference to the underlying value.
Exceptions
BadOptionalAccessif the optional is empty.

◆ value_or() [1/2]

template<typename T>
template<typename U>
T grem::Optional< T >::value_or ( U && defaultValue) const &
inlinenodiscardconstexpr

Get the underlying value, or a fallback value in case the optional is empty.

Parameters
defaultValuevalue to return in case the optional is empty.
Returns
a copy of the underlying value, or the given default value if the optional is empty.

◆ value_or() [2/2]

template<typename T>
template<typename U>
T grem::Optional< T >::value_or ( U && defaultValue) &&
inlinenodiscardconstexpr

Get the underlying value, or a fallback value in case the optional is empty.

Parameters
defaultValuevalue to return in case the optional is empty.
Returns
a move of the underlying value, or the given default value if the optional is empty.

◆ and_then() [1/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::and_then ( F && f) &
inlineconstexpr

Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept a reference to the underlying value as a parameter.
Returns
the result of the function invocation, or a default-constructed value of the function's return type if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ and_then() [2/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::and_then ( F && f) const &
inlineconstexpr

Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept a read-only reference to the underlying value as a parameter.
Returns
the result of the function invocation, or a default-constructed value of the function's return type if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ and_then() [3/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::and_then ( F && f) &&
inlineconstexpr

Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept an rvalue reference to the underlying value as a parameter.
Returns
the result of the function invocation, or a default-constructed value of the function's return type if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ and_then() [4/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::and_then ( F && f) const &&
inlineconstexpr

Invoke a function with the underlying value, or return a default-constructed result in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept a read-only rvalue reference to the underlying value as a parameter.
Returns
the result of the function invocation, or a default-constructed value of the function's return type if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ transform() [1/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::transform ( F && f) &
inlineconstexpr

Invoke a function with the underlying value, or return an empty optional in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept a reference to the underlying value as a parameter.
Returns
the result of the function invocation, or an empty optional if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ transform() [2/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::transform ( F && f) const &
inlineconstexpr

Invoke a function with the underlying value, or return an empty optional in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept a read-only reference to the underlying value as a parameter.
Returns
the result of the function invocation, or an empty optional if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ transform() [3/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::transform ( F && f) &&
inlineconstexpr

Invoke a function with the underlying value, or return an empty optional in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept an rvalue reference to the underlying value as a parameter.
Returns
the result of the function invocation, or an empty optional if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ transform() [4/4]

template<typename T>
template<typename F>
auto grem::Optional< T >::transform ( F && f) const &&
inlineconstexpr

Invoke a function with the underlying value, or return an empty optional in case the optional is empty.

Parameters
ffunction to invoke, which must be able to accept a read-only rvalue reference to the underlying value as a parameter.
Returns
the result of the function invocation, or an empty optional if the optional is empty.
Exceptions
anyexception thrown by the given function.

◆ or_else() [1/2]

template<typename T>
template<typename F>
Optional grem::Optional< T >::or_else ( F && f) const &
inlineconstexpr

Get an optional containing the underlying value, or the result of a function in case the optional is empty.

Parameters
ffunction to invoke in case the optional is empty.
Returns
a copy of the optional, or the result of the given function if the optional is empty.

◆ or_else() [2/2]

template<typename T>
template<typename F>
Optional grem::Optional< T >::or_else ( F && f) &&
inlineconstexpr

Get an optional containing the underlying value, or the result of a function in case the optional is empty.

Parameters
ffunction to invoke in case the optional is empty.
Returns
a move of the optional, or the result of the given function if the optional is empty.

◆ swap()

template<typename T>
void grem::Optional< T >::swap ( Optional< T > & other)
inlineconstexprnoexcept

Swap this optional's value with that of another.

Parameters
otheroptional to swap with.
Exceptions
anyexception thrown by the underlying constructor, assignment or swap implementation of the value type.

◆ reset()

template<typename T>
void grem::Optional< T >::reset ( )
inlineconstexprnoexcept

Destroy the underlying value if present and reset the optional to an empty state.

◆ emplace() [1/2]

template<typename T>
template<typename... Args>
requires (std::is_constructible_v<T, Args...>)
T & grem::Optional< T >::emplace ( Args &&... args)
inlineconstexpr

Construct a new underlying value, destroying the old value if present.

Parameters
argsarguments to pass to the new value's constructor.
Exceptions
anyexception thrown by the underlying constructor of the value type.

◆ emplace() [2/2]

template<typename T>
template<typename U, typename... Args>
requires (std::is_constructible_v<T, std::initializer_list<U>&, Args...>)
T & grem::Optional< T >::emplace ( std::initializer_list< U > ilist,
Args &&... args )
inlineconstexpr

Construct a new underlying value, with an initializer list as the first constructor argument, destroying the old value if present.

Parameters
ilistfirst argument to pass to the new value's constructor.
argssubsequent arguments to pass to the new value's constructor.
Exceptions
anyexception thrown by the underlying constructor of the value type.

◆ swap

template<typename T>
void swap ( Optional< T > & a,
Optional< T > & b )
friend

Swap the values of two optionals.

Parameters
afirst optional.
bsecond optional.
Exceptions
anyexception thrown by the underlying constructor, assignment or swap implementation of the value type.

The documentation for this class was generated from the following file: