template<> for the explicit specialization of a member enumeration

According to 17.7.3 [temp.expl.spec] paragraph 5 (N4659),

... Members of an explicitly specialized class template are defined in the same manner as members of normal classes, and not using the template<> syntax. The same is true when defining a member of an explicitly specialized member class. However, template<> is used in defining a member of an explicitly specialized member class template that is specialized as a class template.

The explicit specialization of E definitely does not belong to the bold case, and it still needs template<>. Why is that?

template<class T> struct A {
    enum E : T;
};

template<> enum A<int>::E : int { eint };

Upvotes: 4

Views: 181

Answers (1)

Vaughn Cato
Vaughn Cato

Reputation: 64298

This paragraph is related to members of an explicitly specialized class template, but you have not explicitly specialized the class template. This is an example of the case it is talking about:

template<class T> struct A {
    enum E : T;
};

template<> struct A<int> {
    enum E : int;
};

enum A<int>::E : int { eint }; // no template<> here

In your example code, you have explicitly specialized a member of the primary template, which does require using template<>, as specified in the first paragraph.

1 An explicit specialization of any of the following:

...

(1.7) — member enumeration of a class template

...

can be declared by a declaration introduced by template<>; that is: explicit-specialization: template < > declaration

The underlying principle behind paragraph 5 is that once you've explicitly specialized a template, it is no longer a template, and you work with the specialization just like you would any other non-template entity.

Upvotes: 6

Related Questions