Учитывая этот тип:
template<typename ...As>
struct Base {};
Мне нужно реализовать функцию
template<int i, typename ...As>
constexpr auto Tail() {
static_assert(i < sizeof...(As), "index out of range");
return ??;
}
, который возвращает экземпляр B
, используя хвост списка параметров типа из индекса i
.
Например,
Tail<0, int, float, double>() -> Base<int, float, double>
Tail<1, int, float, double>() -> Base<float, double>
Tail<2, int, float, double>() -> Base<double>
Tail<3, int, float, double>() -> fails with static assert
Я знаю, как получить тип по индексу i
:
template <int64_t i, typename T, typename... Ts>
struct type_at
{
static_assert(i < sizeof...(Ts) + 1, "index out of range");
typedef typename type_at<i - 1, Ts...>::type type;
};
template <typename T, typename... Ts> struct type_at<0, T, Ts...> {
typedef T type;
};
но я не могу получить рабочую версию для всей проблемы.