jeudi 13 décembre 2018

Partial specialization with more template parameters

Is a partial specialization allowed to have more template parameters than the primary template? My understanding was that the a partial specialization must have either lesser or the same number of template parameters as the primary template.

I am reading C++ Templates (2nd Edition) and in that it is mentioned on Section 5.4 (Page 72) that

template <typename T, std::size_t SZ>
struct MyClass<T[SZ]>{
    static void print(){}
};

and

template <typename T, std::size_t SZ>
struct MyClass<T (&)[SZ]>{
    static void print(){}
};

are both partial specializations of the primary template

template <typename T>
struct MyClass;

The accompanying code works fine. But is this correct? Can a partial specialization have more template parameters than the primary template?

Aucun commentaire:

Enregistrer un commentaire