Go to the documentation of this file.
9 #ifndef EAGINE_OPTIONAL_REF_HPP
10 #define EAGINE_OPTIONAL_REF_HPP
27 : _ptr{std::addressof(ref)} {}
55 return _ptr !=
nullptr;
60 explicit operator bool() const noexcept {
66 auto get() const noexcept -> T& {
73 auto value() const noexcept -> const T& {
82 -> std::enable_if_t<std::is_convertible_v<U, T>, T> {
86 return T(std::forward<U>(fallback));
91 explicit operator T&()
const noexcept {
99 return l.value() == r;
108 return l.value() != r;
119 template <
typename T>
126 template <
typename T>
137 template <
typename T,
typename F>
139 -> std::enable_if_t<std::is_convertible_v<F, T>, T> {
143 return T{std::forward<F>(fallback)};
148 #endif // EAGINE_OPTIONAL_REF_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
Class representing "none" / "nothing" values.
Definition: nothing.hpp:17
static auto extract_or(optional_reference_wrapper< T > ref, T &fallback) noexcept -> T &
Overload of extract_or for optional_reference_wrapper.
Definition: optional_ref.hpp:128
friend auto operator!=(const optional_reference_wrapper &l, const T &r) -> tribool
Tri-state nonequality comparison of the referred instance with a value.
Definition: optional_ref.hpp:105
Optional reference to an instance of type T.
Definition: optional_ref.hpp:23
constexpr optional_reference_wrapper(std::nullptr_t) noexcept
Construction from nullptr.
Definition: optional_ref.hpp:51
constexpr static const indeterminate_t indeterminate
Constant representing unspecified tribool value.
Definition: tribool.hpp:24
optional_reference_wrapper(T &ref) noexcept
Construction from a reference to value of type T.
Definition: optional_ref.hpp:26
friend auto operator==(const optional_reference_wrapper &l, const T &r) -> tribool
Tri-state equality comparison of the referred instance with a value.
Definition: optional_ref.hpp:96
auto is_valid() const noexcept -> bool
Indicates if this stores a valid reference.
Definition: optional_ref.hpp:54
auto get() const noexcept -> T &
Returns the stored reference.
Definition: optional_ref.hpp:66
Tri-state boolean value.
Definition: tribool.hpp:61
auto value() const noexcept -> const T &
Returns the stored value.
Definition: optional_ref.hpp:73
auto value_or(U &&fallback) const noexcept -> std::enable_if_t< std::is_convertible_v< U, T >, T >
Returns the stored value if valid or fallback otherwise.
Definition: optional_ref.hpp:81