diff --git a/include/gp/containers/vector.hpp b/include/gp/containers/vector.hpp index 6956423..1db8cf9 100644 --- a/include/gp/containers/vector.hpp +++ b/include/gp/containers/vector.hpp @@ -160,6 +160,7 @@ namespace gp{ elem.~T(); } gp_config::assertion(alloc.get().deallocate(ary), "could not deallocate"); + ary = nullptr; } } diff --git a/include/gp/functional/optional.hpp b/include/gp/functional/optional.hpp index ef2e0cd..594f823 100644 --- a/include/gp/functional/optional.hpp +++ b/include/gp/functional/optional.hpp @@ -34,7 +34,23 @@ namespace gp{ constexpr optional(T&& value) : ready{true} { - new(buffer) T(gp::forward(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() { @@ -63,10 +79,30 @@ namespace gp{ optional& operator=(T&& value) { if(ready) { - *(T*)buffer = gp::forward(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 { ready = true; - new(buffer) T(gp::forward(value)); + new(buffer) T(gp::move(oth.value())); } return *this; }