You can write apply , which refers to an array and a functor to call with an unpacked array (you can add some excellent redirects, etc.):
template <typename F, typename T, std::size_t N, std::size_t... Idx> decltype(auto) apply_impl (F f, T (&t)[N], std::index_sequence<Idx...>) { return f(t[Idx]...); } template <typename F, typename T, std::size_t N> decltype(auto) apply (F f, T (&t)[N]) { return apply_impl(f, t, std::make_index_sequence<N>{}); }
Then name it like this if foo is a functor class:
apply(foo{}, a);
If foo is just a normal template function, as in your example, you can wrap it in lambda:
apply([](auto...xs){foo(std::forward<decltype(xs)>(xs)...);}, a);
Live demo
source share