Namespaces
Variants
Views
Actions

Talk:cpp/language/templates

From cppreference.com

Looking for the rule about which scope template declarations are legal. E.g., not in block scope, see 14.2. Tmcleod (talk) 14:16, 28 December 2017 (PST)

in the standard, that's [temp]p4. I suppose we could add that here, where currently is the TODO block under Syntax, and/or to the first lines of cpp/language/function_template and cpp/language/class_template --Cubbi (talk) 14:36, 28 December 2017 (PST)

I came across a class-template behavior that deserves a mention: unlike regular classes, class template methods and static data members are instantiated only if they are used OR the template is explicitly instantiated. The standard wording (https://eel.is/c++draft/temp.inst#3.1) is -

The implicit instantiation of a class template specialization causes - the implicit instantiation of the declarations, *but not of the definitions*, of the non-deleted class member functions, member classes, scoped member enumerations, static data members, member templates, and friends.

That is to say - implicit instantiation (as is virtually all instantiations) by itself instantiates only non-static data members. The rest (methods, static members etc) are instantiated only if used.