BAN: Add emplace for Variant

This allows variant to store values that are not copy/move
constructible.
This commit is contained in:
Bananymous 2024-02-07 22:33:16 +02:00
parent 572c4052f6
commit 2cc9534570
1 changed files with 8 additions and 0 deletions

View File

@ -216,6 +216,14 @@ namespace BAN
return m_index == detail::index<T, Ts...>(); return m_index == detail::index<T, Ts...>();
} }
template<typename T, typename... Args>
void emplace(Args&&... args) requires (can_have<T>())
{
clear();
m_index = detail::index<T, Ts...>();
new (m_storage) T(BAN::forward<Args>(args)...);
}
template<typename T> template<typename T>
void set(T&& value) requires (can_have<T>() && !is_lvalue_reference_v<T>) void set(T&& value) requires (can_have<T>() && !is_lvalue_reference_v<T>)
{ {