25 requires requires { !std::is_reference_v<T>; }
55 constexpr optref() noexcept : opt(std::nullopt) {}
61 constexpr optref(std::nullopt_t) noexcept : opt(std::nullopt) {}
76 requires std::convertible_to<U&, T&>
79 if (!other.has_reference())
95 constexpr optref(std::reference_wrapper<T> wrapper) noexcept
116 return this->opt.has_value();
125 explicit constexpr operator bool() const noexcept {
126 return static_cast<bool>(this->opt);
137 return this->opt.value();
148 return this->opt.value();
161 this->opt.swap(other.opt);
173 std::optional<reference_wrapper_type> opt;
A std::optional<std::reference_wrapper<T>> wrapper for lvalue references.
Definition optref.hpp:26
constexpr optref(const optref &other) noexcept
Copy constructor.
Definition optref.hpp:67
constexpr bool has_reference() const noexcept
Does it contain a reference?
Definition optref.hpp:115
constexpr optref(const optref< U > &other) noexcept
Converting copy constructor for base/derived class references.
Definition optref.hpp:77
constexpr optref(std::nullopt_t) noexcept
Nullopt constructor - no reference.
Definition optref.hpp:61
constexpr optref(std::reference_wrapper< T > wrapper) noexcept
Construct an optref from std::reference_wrapper.
Definition optref.hpp:95
std::add_lvalue_reference_t< T > reference_type
Reference type.
Definition optref.hpp:37
void reset() noexcept
Reset (cannot assign after).
Definition optref.hpp:168
constexpr const_reference_type reference() const
Get the contained const reference; throws if none.
Definition optref.hpp:147
constexpr optref(T &reference) noexcept
Construct an optref from reference.
Definition optref.hpp:88
void swap(optref &other) noexcept
Swap implementation.
Definition optref.hpp:160
std::reference_wrapper< value_type > reference_wrapper_type
Reference wrapper type for std::optional.
Definition optref.hpp:49
std::add_const_t< reference_type > const_reference_type
Const reference type.
Definition optref.hpp:43
T value_type
Value type.
Definition optref.hpp:31
constexpr reference_type reference()
Get the contained reference; throws if none.
Definition optref.hpp:136
constexpr optref() noexcept
Default constructor - std::optional contains no reference.
Definition optref.hpp:55
constexpr optref(T *pointer) noexcept
Construct an optref from a pointer.
Definition optref.hpp:102