53 present_ = o.present_;
73 const T* operator->()
const {
77 const T& operator*()
const {
81 operator bool()
const {
85 bool is_present()
const {
89 bool has_value()
const noexcept {
96 throw std::runtime_error(
"Access optional value, which has not been set");
102 const T &value()
const &{
104 throw std::runtime_error(
"Access optional value, which has not been set");
111 throw std::runtime_error(
"Access optional value, which has not been set");
113 return std::move(value_);
116 const T &&value()
const &&{
118 throw std::runtime_error(
"Access optional value, which has not been set");
120 return std::move(value_);
124 return this->value();
128 return this->value();
130 const T &get()
const & {
131 return this->value();
134 const T&& get()
const &&{
135 return this->value();
138 T value_or(U &&default_value)
const &{
139 return bool(*
this) ? **this :
static_cast<T
>(std::forward<U>(default_value));
143 T value_or(U &&default_value) &&{
144 return bool(*
this) ? std::move(**
this) :
static_cast<T
>(std::forward<U>(default_value));
148 if (this->present_ && other.present_)
return this->get() == *other;
149 if ((!this->present_) && (!other.present_))
return true;
153 bool operator==(
const T& val)
const {
154 if (this->present_)
return this->get() == val;
163 void set(
const T& v) {