diff --git a/BAN/include/BAN/Optional.h b/BAN/include/BAN/Optional.h index 7f31c237..10dc2d7c 100644 --- a/BAN/include/BAN/Optional.h +++ b/BAN/include/BAN/Optional.h @@ -15,11 +15,17 @@ namespace BAN Optional(); Optional(const T&); Optional(T&&); + template + Optional(Args&&...); + ~Optional(); Optional& operator=(const Optional&); Optional& operator=(Optional&&); + template + Optional& emplace(Args&&...); + T* operator->(); const T* operator->() const; @@ -58,6 +64,14 @@ namespace BAN new (m_storage) T(BAN::move(value)); } + template + template + Optional::Optional(Args&&... args) + : m_has_value(true) + { + new (m_storage) T(BAN::forward(args)...); + } + template Optional::~Optional() { @@ -73,6 +87,7 @@ namespace BAN m_has_value = true; new (m_storage) T(other.value()); } + return *this; } template @@ -84,6 +99,17 @@ namespace BAN m_has_value = true; new (m_storage) T(BAN::move(other.release_value())); } + return *this; + } + + template + template + Optional& Optional::emplace(Args&&... args) + { + clear(); + m_has_value = true; + new (m_storage) T(BAN::forward(args)...); + return *this; } template