Syntax for defining a member of an explicitly specialized class template

47 views
Skip to first unread message

razvyb...@gmail.com

unread,
Apr 12, 2018, 12:21:32 PM4/12/18
to ISO C++ Standard - Discussion
On this page describing explicit template specialization there is the following paragraph (emphasis is mine):

When defining a member of an explicitly specialized class template outside the body of the class, the syntax template <> is not used, except if it's a member of an explicitly specialized member class template, which is specialized as a class template, because otherwise, the syntax would require such definition to begin with template<parameters> required by the nested template


I have some questions regarding the whole paragraph.

First, there is the exception: "except if it's a member of an explicitly specialized member class template, which is specialized as a class template". Does "which" refer to the "explicitly specialized member class template"?
Let's look at the example from the site:

template< typename T>
struct A {
    struct B {};  // member class 
    template<class U> struct C { }; // member class template
};
 
template<> // specialization of a member class template
template<class U> struct A<char>::C {
    void f();
};

I believe "which" refers to A<char>::C, but I want to make sure. 


My second question is related to the last part of the paragraph: "because otherwise, the syntax would require such definition to begin with template<parameters> required by the nested template". Does "otherwise" refer to the case in which template<> would not be used when "defining a member of an explicitly specialized member class template, which is specialized as a class template"?

If so, what would be the problem with writing 

template<class U> void A<char>::C<U>::f() { /* ... */ }

instead of 

template<>
template<class U> void A<char>::C<U>::f() { /* ... */ }

?
 
Thank you. 

razvyb...@gmail.com

unread,
Apr 13, 2018, 5:13:24 PM4/13/18
to ISO C++ Standard - Discussion, razvyb...@gmail.com
Is it because

template<class U> void A<char>::C<U>::f() { /* ... */ }

could be interpreted as if f() were a template taking as template parameter U?

razvyb...@gmail.com

unread,
Apr 14, 2018, 8:55:08 AM4/14/18
to ISO C++ Standard - Discussion, razvyb...@gmail.com
I found this issue which lead me to this document.
I think that the exception for "a member of an explicitly specialized member class template, which is specialized as a class template" was added to the standard just because that is the syntax required by compiler implementations.


On Thursday, April 12, 2018 at 7:21:32 PM UTC+3, razvyb...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages