In c++, how can I implement a function with an int template argument indicating the tuple length and produce a std::tuple with that length?
E.g.
func<
If you're okay with a C++14 solution, Ryan's answer is the way to go.
With C++11, you can do the following (still based on index_sequence
, but that's implementable in C++11):
template >
struct n_tuple;
template
struct n_tuple> {
template
using ignore = T;
using type = std::tuple...>;
};
template
using n_tuple_t = typename n_tuple::type;
With that:
template
n_tuple_t func() {
return n_tuple_t{};
}