Calculate argument type for Variadic template?

Is there a way to infer the type of the list in order to avoid having to pass the type of the argument that should be in the list, just infer it from the first type of element.

template<typename T, T... Args> struct Calc { // do stuff with Args }; // Usage: Calc<int, 1, 2, 3>::value; typename<T... Args> Calc { }; // error T undefined // Desired: Calc<1, 2, 3>::value; // auto deduced T = int Calc<1.0f, 2.0f, 3.0f>::value; // auto deduced T = float 

Is there a way to get the desired behavior, or should I include this type as a parameter?

+5
source share
1 answer

As far as I know, this is not possible before C ++ 14. However, in C ++ 17, user-defined subtraction guides are described in detail: output of the template template argument

0
source

Source: https://habr.com/ru/post/1202913/


All Articles