Topic: Can we explicit instantiate a class template inside of a class
Author: dhb2000@gmail.com (Barry)
Date: Wed, 28 Nov 2007 15:31:47 GMT Raw View
Jerry Coffin wrote:
> On Nov 20, 7:41 am, dhb2...@gmail.com (Barry) wrote:
>> Can we explicit instantiate a class template inside of a class or
>> a function?
>>
>> according to my understanding, The answer is NO,explicit template
>> instantiation should take place in a namespace scope, not
>> a class scope, not a function scope.
>>
>> And the I think where supports my answer is here:
>>
>> 14.7.2/5
>> An explicit instantiation of a class or function template
>> specialization is placed in the namespace in which the template is
>> defined.
>>
>> Do I interpret the para right?
>
> I don't think so. To mean that, the standard would (or at least
> should) use the word "shall" -- i.e. the wording would be:
>
> An explicit instantiation of a class or function template
> specialization shall be
> placed in the namespace in which the template is defined.
>
> As it stands right now, it's written not as a requirement, but as
> information about what WILL happen. IOW, you can put the code for the
> explicit instantiation essentially anywhere you want to, but
> regardless of where you put that code, the instantiation will take
> place in the scope of the namespace in which the template is defined.
>
Catching up the URL given by Diaiel (thanks :-) )
Proposed resolution (suggested 04/01, proposed 10/01):
(The first change below will need to be revised in accordance with the
resolution of issue 284 to add a cross-reference to the text dealing
with class names.)
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#275
*Proposed resolution (suggested 04/01, proposed 10/01):*
Add in 14.7.2 [temp.explicit] paragraph 2 before the example:
An explicit instantiation shall appear in an enclosing namespace of its
template. If the name declared in the explicit instantiation is an
unqualified name, the explicit instantiation shall appear in the
namespace where its template is declared. [Note: Regarding qualified
names in declarators, see 8.3 [dcl.meaning].]
//////////
My understanding about explicit instantiation/specialization is that
they should be both placed in a namespace, (except declaring a
specialization as friend, which only does name injection).
Think about it, if we allow explicit instantiation/specialization in a
function/class, then how do we explain the visibility of such
specialization/instantiation? I think this will bring more complexity.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]