23 auto src = other.value_ptr();
25 set_value(std::move(*src));
36 set_value(std::move(value));
41 set_value(rhs.value());
46 if(other.has_value()) {
47 set_value(other.value());
55 explicit operator bool()
const {
59 bool has_value()
const {
return has_value_; }
61 const T& value()
const {
71 T value_or(T&& def)
const {
72 bool(*
this) ? **this :
static_cast<T
>(std::forward<T>(def));
76 return bool(*
this) ? std::move(**
this) :
static_cast<T
>(std::forward<T>(def));
79 const T* operator->()
const {
89 const T& operator*()
const {
100 uint8_t data_[
sizeof(T)] __attribute__((aligned(8)));
101 bool has_value_ =
false;
103 T* value_ptr()
const {
104 return (has_value()) ? (T*) (data_) :
nullptr;
107 void set_value(
const T& value) {
114 *(value_ptr()) = value;
117 void set_value(T&& value) {
123 new (data_) T(std::move(value));