From 8794122c2da1f244866b780106ebddb9cd5c15c9 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 7 Feb 2026 18:52:40 +0200 Subject: [PATCH] BAN: Variant allow copy/move from empty --- BAN/include/BAN/Variant.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/BAN/include/BAN/Variant.h b/BAN/include/BAN/Variant.h index 0cdc8569..a88c2d31 100644 --- a/BAN/include/BAN/Variant.h +++ b/BAN/include/BAN/Variant.h @@ -126,14 +126,16 @@ namespace BAN Variant(Variant&& other) : m_index(other.m_index) { - detail::move_construct(other.m_index, other.m_storage, m_storage); + if (other.has_value()) + detail::move_construct(other.m_index, other.m_storage, m_storage); other.clear(); } Variant(const Variant& other) : m_index(other.m_index) { - detail::copy_construct(other.m_index, other.m_storage, m_storage); + if (other.has_value()) + detail::copy_construct(other.m_index, other.m_storage, m_storage); } template @@ -157,12 +159,13 @@ namespace BAN Variant& operator=(Variant&& other) { - if (m_index == other.m_index) + if (m_index == other.m_index && m_index != invalid_index()) detail::move_assign(m_index, other.m_storage, m_storage); else { clear(); - detail::move_construct(other.m_index, other.m_storage, m_storage); + if (other.has_value()) + detail::move_construct(other.m_index, other.m_storage, m_storage); m_index = other.m_index; } other.clear(); @@ -171,12 +174,13 @@ namespace BAN Variant& operator=(const Variant& other) { - if (m_index == other.m_index) + if (m_index == other.m_index && m_index != invalid_index()) detail::copy_assign(m_index, other.m_storage, m_storage); else { clear(); - detail::copy_construct(other.m_index, other.m_storage, m_storage); + if (other.has_value()) + detail::copy_construct(other.m_index, other.m_storage, m_storage); m_index = other.m_index; } return *this;