How to detect the first and the last argument in the variadic templates?
For the 1st argument it is easy (just compare sizeof...(T) with 0), but is ther
I'm not positive if this is what you want. But here are two utilities named first and last that take variadic templates and typedef the first and last type respectively:
#include
#include
template
struct first
{
typedef T1 type;
};
template
struct last
{
typedef typename last::type type;
};
template
struct last
{
typedef T1 type;
};
template
struct A
{
typedef typename first::type first;
typedef typename last::type last;
};
struct B1 {};
struct B2 {};
struct B3 {};
int main()
{
typedef A T;
std::cout << typeid(T::first).name() << '\n';
std::cout << typeid(T::last).name() << '\n';
}