Fixed existing initializer_list member functions

Added additional initializer_list member functions
This commit is contained in:
John Wellbelove 2024-03-10 20:21:30 +00:00
parent a77e435924
commit 46b636694d

View File

@ -701,6 +701,29 @@ namespace etl
return *static_cast<T*>(data);
}
#if ETL_HAS_INITIALIZER_LIST
//***************************************************************************
/// Emplace by type with variadic constructor parameters.
//***************************************************************************
template <typename T, typename U, typename... TArgs>
T& emplace(std::initializer_list<U> il, TArgs&&... args)
{
static_assert(etl::is_one_of<T, TTypes...>::value, "Unsupported type");
using type = etl::remove_cvref_t<T>;
operation(private_variant::Destroy, data, nullptr);
construct_in_place_args<type>(data, il, etl::forward<TArgs>(args)...);
operation = operation_type<type, etl::is_copy_constructible<type>::value, etl::is_move_constructible<type>::value>::do_operation;
type_id = etl::private_variant::parameter_pack<TTypes...>::template index_of_type<T>::value;
return *static_cast<T*>(data);
}
#endif
//***************************************************************************
/// Emplace by index with variadic constructor parameters.
//***************************************************************************
@ -722,6 +745,29 @@ namespace etl
return *static_cast<type*>(data);
}
#if ETL_HAS_INITIALIZER_LIST
//***************************************************************************
/// Emplace by index with variadic constructor parameters.
//***************************************************************************
template <size_t Index, typename U, typename... TArgs>
typename etl::variant_alternative<Index, variant<TArgs...>>::type& emplace(std::initializer_list<U> il, TArgs&&... args)
{
static_assert(Index < etl::private_variant::parameter_pack<TTypes...>::size, "Index out of range");
using type = typename etl::private_variant::parameter_pack<TTypes...>::template type_from_index<Index>::type;
operation(private_variant::Destroy, data, nullptr);
construct_in_place_args<type>(data, il, etl::forward<TArgs>(args)...);
operation = operation_type<type, etl::is_copy_constructible<type>::value, etl::is_move_constructible<type>::value>::do_operation;
type_id = Index;
return *static_cast<type*>(data);
}
#endif
//***************************************************************************
/// Move assignment operator for type.
///\param value The value to assign.