|
@ -34,7 +34,23 @@ namespace gp{ |
|
|
constexpr optional(T&& value) |
|
|
constexpr optional(T&& value) |
|
|
: ready{true} |
|
|
: ready{true} |
|
|
{ |
|
|
{ |
|
|
new(buffer) T(gp::forward<T>(value)); |
|
|
|
|
|
|
|
|
new(buffer) T(gp::move(value)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constexpr optional(const optional& oth) |
|
|
|
|
|
: ready{oth.ready} |
|
|
|
|
|
{ |
|
|
|
|
|
if(ready) { |
|
|
|
|
|
new(buffer) T(oth.value()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
constexpr optional(optional&& oth) |
|
|
|
|
|
: ready{oth.ready} |
|
|
|
|
|
{ |
|
|
|
|
|
if(ready) { |
|
|
|
|
|
new(buffer) T(gp::move(oth.value())); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
~optional() { |
|
|
~optional() { |
|
@ -63,10 +79,30 @@ namespace gp{ |
|
|
|
|
|
|
|
|
optional& operator=(T&& value) { |
|
|
optional& operator=(T&& value) { |
|
|
if(ready) { |
|
|
if(ready) { |
|
|
*(T*)buffer = gp::forward<T>(value); |
|
|
|
|
|
|
|
|
*(T*)buffer = gp::move(value); |
|
|
|
|
|
} else { |
|
|
|
|
|
ready = true; |
|
|
|
|
|
new(buffer) T(gp::move(value)); |
|
|
|
|
|
} |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
optional& operator=(const optional& oth) { |
|
|
|
|
|
if(ready) { |
|
|
|
|
|
*(T*)buffer = oth.value(); |
|
|
|
|
|
} else { |
|
|
|
|
|
ready = true; |
|
|
|
|
|
new(buffer) T(oth.value()); |
|
|
|
|
|
} |
|
|
|
|
|
return *this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
optional& operator=(optional&& oth) { |
|
|
|
|
|
if(ready) { |
|
|
|
|
|
*(T*)buffer = gp::move(oth.value()); |
|
|
} else { |
|
|
} else { |
|
|
ready = true; |
|
|
ready = true; |
|
|
new(buffer) T(gp::forward<T>(value)); |
|
|
|
|
|
|
|
|
new(buffer) T(gp::move(oth.value())); |
|
|
} |
|
|
} |
|
|
return *this; |
|
|
return *this; |
|
|
} |
|
|
} |
|
|