tuple/value: fix various compile time errors

This commit is contained in:
Danny Robson 2022-02-09 16:33:44 +10:00
parent d096eb9d21
commit ceda32b912

View File

@ -250,24 +250,31 @@ namespace cruft::tuple::value {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
namespace detail { namespace detail {
template <typename FunctionT, typename TupleT, size_t ...Index> template <typename FunctionT, typename TupleT, size_t ...Index>
requires ( // requires (
std::is_convertible_v< // std::is_convertible_v<
std::tuple_element_t<Index, TupleT>, // std::tuple_element_t<Index, TupleT>,
std::common_type< // std::common_type<
std::tuple_element_t<Index, TupleT>... // std::tuple_element_t<Index, TupleT>...
> // >
> && ... // > && ...
) // )
auto auto
transform_array (index::indices<Index...>, FunctionT &&func, TupleT &&val) transform_array (std::index_sequence<Index...>, FunctionT &&func, TupleT &&val)
{ {
using value_type = std::common_type< using value_type = std::common_type_t<
std::tuple_element_t<Index, TupleT>... std::invoke_result_t<
FunctionT,
std::tuple_element_t<Index, std::remove_cvref_t<TupleT>>
>...
>; >;
return std::array<value_type, std::tuple_size_v<TupleT>> ( constexpr auto arity = std::tuple_size_v<
std::invoke (func, std::get<Index> (val))... std::remove_cvref_t<TupleT>
); >;
return std::array<value_type, arity> { {
value_type (std::invoke (func, std::get<Index> (val)))...
} };
} }
} }
@ -281,9 +288,14 @@ namespace cruft::tuple::value {
auto auto
transform_array (FunctionT &&func, TupleT &&val) transform_array (FunctionT &&func, TupleT &&val)
{ {
return transform_array ( return detail::transform_array (
std::make_index_sequence<
std::tuple_size_v<
std::remove_cvref_t<TupleT>
>
> {},
std::forward<FunctionT> (func), std::forward<FunctionT> (func),
std::forward<TupleT> (val) std::forward<TupleT > (val )
); );
} }
} }