According to the C++17 standard, [temp.point]/4, emphasis mine,
For a class template specialization, a class member template specialization, or a specialization for a class member of a class template, if the specialization is implicitly instantiated because it is referenced from within another template specialization, if the context from which the specialization is referenced depends on a template parameter, and if the specialization is not instantiated previous to the instantiation of the enclosing template, the point of instantiation is immediately before the point of instantiation of the enclosing template. Otherwise, the point of instantiation for such a specialization immediately precedes the namespace scope declaration or definition that refers to the specialization.
I don't understand how to interpret this sentence. Elsewhere, when describing name lookup in templates, the standard refers to the "instantiation context" and the "definition context". There, the word "context" seems to mean a particular point in the source text, which determines the set of visible names. Here, I'm not sure if the meaning of "context" is the same. If that is what it means, I'm not sure what it means for it to depend on a template parameter. Does that mean it's inside a template, or does it specifically mean there are still some unbound template parameters from enclosing templates at the point where the compiler decides to instantiate the specialization in question, or something else?
Examples would be appreciated.
This context appears inside an enclosing template (from within another template specialization and depends on a template parameter). It must depends on a template parameter of the enclosing template, so it may be a context inside the definition context of the enclosing template.
So I suppose this paragraph could be illustrated by this example:
template<class T> struct A{};
template<class T> struct B{};
//point of instantiation of B<int>
template<class T> void f(){
A<T> a; //The context depends on enclosing template parameter T
B<int> b; //The context does not depend on a template parameter.
}
//
void g(){
f<double>();
}
//point of instantiation of A<double>
//point of instantiation of f<double>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With