I'm trying to implement a way of removing some types from a tuple; for instance I want to be able to e.g. only take a tuple of the first 2 template arguments for a tuple depending on a condition:
- Is it possible to 'pack' the types of which a tuple consists back into a parameter pack? (tuple -> typename... contained_types)
- Is it possible to combine a param. pack with a typename (e.g. use "Pack1..., Pack2..." specifying a single parameter pack for a struct?
#include <cstdint>
#include <tuple>
template <typename... tpl> struct Helper {
template <std::size_t rem, typename curr, typename... rest> struct take {
using type = Helper<(tpl..., curr)>::take<rem-1, rest...>::type; // here, I'm trying (2.)
};
template <typename curr, typename... rest> struct take<0, curr, rest...> {
using type = std::tuple<tpl...>;
};
};
template <std::size_t s, typename... tpl> using take_t = Helper<>::take<s, tpl...>;
int main() {
take_t<2, int, int, int> k = std::make_tuple(1, 2);
}
edit The line Helper fails with the following message:
/home/juli/test.cc:6:18: error: need ‘typename’ before ‘Helper<tpl ..., curr>::take’ because ‘Helper<tpl ..., curr>’ is a dependent scope
6 | using type = Helper<tpl..., curr>::take<rem-1, rest...>::type;
and when I provide typename
/home/juli/test.cc:6:53: error: expected ‘;’ before ‘<’ token
6 | using type = typename Helper<tpl..., curr>::take<rem-1, rest...>::type;
edit2 I achieved this via [helper functions](https://gist.github.com/juliusHuelsmann/669f537aeb5e7105386d510d186b24e1 ), but those fail with non primitive types when the constructor is not constexpr so I cannot use it in my use case and am curious to know how to achieve this and why my approach failed.