I have the following code:
template<auto... args> struct Custom
{
};
int main()
{
Custom<1, nullptr> s; // i want this to succeed only when all the template arguments are of the same type
}
As is evident from the above code, i can pass template arguments of different types. My question is that is there a way to only accept template arguments of the same type. This means, that the statement inside the main
should fail and should only work when all the template arguments are of the same type. Essentially, there are 2 requirements:
I don't if this is even possible. I was thinking of maybe using enable_if
or some other feature but i don't know what might help here.
You can make use of the decltype
construct as shown below:
template<auto T1, decltype(T1)... Args> struct Custom
{
};