Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get typedef from parameter pack

I have a struct of this form:

template <typename T>
struct X
{
    using value = T;
};

I am passing one or more of these to a template function like this:

template <typename... Ts>
void Func(Ts... ts);

What I really want is to explicitly list the Xs and have the function parameter types be the values of the Ts. How would I do that?

like image 674
Graznarak Avatar asked May 26 '16 03:05

Graznarak


1 Answers

The following works for me.

template <typename T>
struct X
{
    using value = T;
};

template <typename T>
struct Y
{
    using value = T*;
};

template <typename... Ts>
void Func(typename Ts::value... ts)
{
}

int main()
{
   Func<X<int>, Y<double>>(10, nullptr);
}
like image 50
R Sahu Avatar answered Sep 21 '22 13:09

R Sahu