diff --git a/include/continuable/detail/variant.hpp b/include/continuable/detail/variant.hpp index 68f0a37..dbd303c 100644 --- a/include/continuable/detail/variant.hpp +++ b/include/continuable/detail/variant.hpp @@ -222,16 +222,19 @@ public: template , T...>::value> - explicit optional_variant(V&& value) // + // Since the optional_variant is never a part of the contained + // values itself this overload is safed against the linted issue. + // NOLINTNEXTLINE(misc-forwarding-reference-overload) + explicit optional_variant(V&& value) : optional_variant(std::forward(value), Index) { } - optional_variant& operator=(T value) { - set_value(std::move(value)); - return *this; - } - optional_variant& operator=(types::error_type error) { - set_exception(std::move(error)); + template , T...>::value> + optional_variant& operator=(V&& value) { + weak_destroy(); + init(std::forward(value)); + set_slot(Index); return *this; } @@ -249,6 +252,18 @@ public: return !is_empty(); } + template + V& cast() noexcept { + assert(!is_slot(traits::index_of_t, T...>::value)); + return *reinterpret_cast*>(&this->storage_); + } + + template + V const& cast() const noexcept { + assert(!is_slot(traits::index_of_t, T...>::value)); + return *reinterpret_cast const*>(&this->storage_); + } + private: template void visit(V&& visitor) { @@ -275,17 +290,6 @@ private: } } - template - V& cast() noexcept { - assert(!is_empty()); - return *reinterpret_cast(&this->storage_); - } - template - V const& cast() const noexcept { - assert(!is_empty()); - return *reinterpret_cast(&this->storage_); - } - template void init(V&& value) { assert(is_empty());