Search code examples
c++templatespartial-specialization

Is there a way a partial specialization is always preferred over the primary template?


I'm asking myself

Can you write a class template and a corresponding partial specialization such that for any set of template arguments for the parameters, the partial specialization is taken by the compiler?

For example

template<typename T>
struct A { };

template<typename T>
struct A</* what to write!?*/> { };

I seem to remember having read that this is possible somehow, but I forgot the exact algorithm to make this work.


Solution

  • My version of GCC is happy to accept:

    template<typename T>
    struct A;
    
    template<typename... Pack>
    struct A<Pack...> {};