tuple: add a map function over a tuple

This commit is contained in:
Danny Robson 2018-03-13 14:38:51 +11:00
parent 741012151b
commit f4465329c8

View File

@ -22,6 +22,7 @@
#include <tuple>
#include <type_traits>
#include <functional>
namespace util::tuple {
@ -165,6 +166,29 @@ namespace util::tuple {
};
///////////////////////////////////////////////////////////////////////////
namespace detail {
template <typename FuncT, typename ArgT, std::size_t ...Indices>
auto
convert (std::index_sequence<Indices...>, FuncT &&func, ArgT &&arg)
{
return std::tuple (std::invoke (func, std::get<Indices> (arg))...);
}
};
template <
typename FuncT,
typename ArgT,
typename IndicesV = std::make_index_sequence<
std::tuple_size_v<std::decay_t<ArgT>>
>
>
auto convert (FuncT &&func, ArgT &&arg)
{
return detail::convert (IndicesV{}, func, arg);
}
///////////////////////////////////////////////////////////////////////////
/// do nothing with a set of parameters.
///