I define a variadic struct like so
template <class T, class... TRest>
struct Opa
{
Opa()
{
std::cout << "Mutiple-arguments template";
}
};
and want to specialize it for the case with 1 argument only as follows
template <>
struct Opa<class T>
{
Opa()
{
std::cout << "One-argument template";
}
};
but compiler just ignores this second struct, and the output from
Opa<int> opa;
Opa<int, int> opa_opa;
is Mutiple-arguments template, Mutiple-arguments template.
Specifying one-argument template in different ways, e.g.
template <class T>
struct Opa
{...}
resulted in a compilation error. I realize that my question is quite simple, but googling didn't help. So please don't throw rotten tomatoes at me, and thanks for the answers.
Your syntax for the single-argument specialisation is wrong. You're probably fully specialising it for an on-the-spot declared class T. You wanted this:
template <class T>
struct Opa<T>
{
Opa()
{
std::cout << "One-argument template";
}
};
Live example
Partial specialisations are declared by listing the parameters of the partial specialisation in the angle brackets after template (in your case, a single type parameter, class T), and listing the arguments for the primary template in the angle brackets after the primary template's name (in your case, a single type argument, T).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With