diff --git a/tuple/value.hpp b/tuple/value.hpp index 424920ba..c037158b 100644 --- a/tuple/value.hpp +++ b/tuple/value.hpp @@ -245,4 +245,45 @@ namespace cruft::tuple::value { std::forward (val) ); } + + + /////////////////////////////////////////////////////////////////////////// + namespace detail { + template + requires ( + std::is_convertible_v< + std::tuple_element_t, + std::common_type< + std::tuple_element_t... + > + > && ... + ) + auto + transform_array (index::indices, FunctionT &&func, TupleT &&val) + { + using value_type = std::common_type< + std::tuple_element_t... + >; + + return std::array> ( + std::invoke (func, std::get (val))... + ); + } + } + + + ///------------------------------------------------------------------------ + /// Transform each element of a tuple with the supplied function and + /// return an array of the return values. + /// + /// The function must return types that have a computable common type. + template + auto + transform_array (FunctionT &&func, TupleT &&val) + { + return transform_array ( + std::forward (func), + std::forward (val) + ); + } }