Jarod42 slightly extended approach for lazies (C ++ 17):
#include <utility> #include <array> struct blah {}; template <class T, std::size_t I> using typer = T; template <class T, std::size_t N, class = std::make_index_sequence<N>> struct bar_impl; template <class T, std::size_t N, std::size_t... Is> struct bar_impl<T, N, std::index_sequence<Is...>> { static auto foo(typer<T, Is>... ts) { return std::array<T, N>{{ts...}}; } }; template <class T = blah, std::size_t N = 10, class = std::make_index_sequence<N>> struct bar; template <class T, std::size_t N, std::size_t... Is> struct bar<T, N, std::index_sequence<Is...>>: bar_impl<T, Is>... { using bar_impl<T, Is>::foo...; }; int main() { bar<>::foo({}, {}); }
[live demo]
Edit:
Some C ++ 14 solution that (as max66 pointed out) is even simpler than I expected:
#include <utility> #include <array> struct blah {}; template <class T, std::size_t I> using typer = T; template <class T = blah, std::size_t N = 10, class = std::make_index_sequence<N>> struct bar; template <class T, std::size_t N, std::size_t... Is> struct bar<T, N, std::index_sequence<Is...>>: bar<T, N - 1> { using bar<T, N - 1>::foo; static auto foo(typer<T, Is>... ts) { return std::array<T, N>{{ts...}}; } }; template <class T> struct bar<T, 0, std::index_sequence<>> { static auto foo() { return std::array<T, 0>{{}}; } }; int main() { bar<>::foo({}, {}); }
[live demo]
Another edit:
This one (as suggested by Jarod42) provides exactly the same syntax for the call as in the OP question:
#include <utility> #include <array> struct blah {}; template <class T, std::size_t I> using typer = T; template <class T = blah, std::size_t N = 10, class = std::make_index_sequence<N>> struct bar; template <class T, std::size_t N, std::size_t... Is> struct bar<T, N, std::index_sequence<Is...>>: bar<T, N - 1> { using bar<T, N - 1>::operator(); auto operator()(typer<T, Is>... ts) { return std::array<T, N>{{ts...}}; } }; template <class T> struct bar<T, 0, std::index_sequence<>> { auto operator()() { return std::array<T, 0>{{}}; } }; bar<> foo; int main() { foo({}, {}); }
[live demo]