18concept not_reference = !std::is_reference_v<T>;
30 requires not_reference<T>
60 constexpr optref() noexcept : opt(std::nullopt) {}
66 constexpr optref(std::nullopt_t) noexcept : opt(std::nullopt) {}
81 requires std::convertible_to<U, T>
84 if (!other.has_reference())
100 constexpr optref(std::reference_wrapper<T> wrapper) noexcept
121 return this->opt.has_value();
130 explicit constexpr operator bool() const noexcept {
131 return static_cast<bool>(this->opt);
142 return this->opt.value();
153 return this->opt.value();
166 this->opt.swap(other.opt);
178 std::optional<reference_wrapper_type> opt;
A std::optional<std::reference_wrapper<T>> wrapper for lvalue references.
Definition optref.hpp:31
constexpr optref(const optref &other) noexcept
Copy constructor.
Definition optref.hpp:72
constexpr bool has_reference() const noexcept
Does it contain a reference?
Definition optref.hpp:120
constexpr optref(std::nullopt_t) noexcept
Nullopt constructor - no reference.
Definition optref.hpp:66
constexpr optref(std::reference_wrapper< T > wrapper) noexcept
Construct an optref from std::reference_wrapper.
Definition optref.hpp:100
std::add_lvalue_reference_t< T > reference_type
Reference type.
Definition optref.hpp:42
void reset() noexcept
Reset (cannot assign after).
Definition optref.hpp:173
constexpr const_reference_type reference() const
Get the contained const reference; throws if none.
Definition optref.hpp:152
constexpr optref(T &reference) noexcept
Construct an optref from reference.
Definition optref.hpp:93
constexpr optref(const optref< U > &other) noexcept
Converting copy constructor for base/derived class references.
Definition optref.hpp:82
void swap(optref &other) noexcept
Swap implementation.
Definition optref.hpp:165
std::reference_wrapper< value_type > reference_wrapper_type
Reference wrapper type for std::optional.
Definition optref.hpp:54
std::add_const_t< reference_type > const_reference_type
Const reference type.
Definition optref.hpp:48
T value_type
Value type.
Definition optref.hpp:36
constexpr reference_type reference()
Get the contained reference; throws if none.
Definition optref.hpp:141
constexpr optref() noexcept
Default constructor - std::optional contains no reference.
Definition optref.hpp:60
constexpr optref(T *pointer) noexcept
Construct an optref from a pointer.
Definition optref.hpp:107