32 auto src = other.value_ptr();
34 set_value(std::move(*src));
45 set_value(std::move(value));
50 set_value(rhs.value());
55 if(other.has_value()) {
56 set_value(other.value());
64 explicit operator bool()
const {
68 bool has_value()
const {
return has_value_; }
70 const T& value()
const {
80 T value_or(
const T& def)
const {
81 return *
this ? **this : def;
84 T value_or(T&& def)
const {
85 return bool(*
this) ? **this :
static_cast<T
>(std::forward<T>(def));
89 return bool(*
this) ? std::move(**
this) :
static_cast<T
>(std::forward<T>(def));
92 const T* operator->()
const {
102 const T& operator*()
const {
112 optional& operator=(
const OptionalInit&) {
118 uint8_t _S_ALIGN(8) data_[
sizeof(T)];
119 bool has_value_ =
false;
121 T* value_ptr()
const {
122 return (has_value()) ? (T*) (data_) :
nullptr;
125 void set_value(
const T& value) {
132 *(value_ptr()) = value;
135 void set_value(T&& value) {
141 new (data_) T(std::move(value));