Стандарт C++ 11, страница 102
Описание файла
PDF-файл из архива "Стандарт C++ 11", который расположен в категории "". Всё это находится в предмете "практикум (прикладное программное обеспечение и системы программирования)" из 4 семестр, которые можно найти в файловом архиве МГУ им. Ломоносова. Не смотря на прямую связь этого архива с МГУ им. Ломоносова, его также можно найти и в других разделах. .
Просмотр PDF-файла онлайн
Текст 102 страницы из PDF
∗/ };template<class T> class Array { /∗ ... ∗/ };template<class T> void sort(Array<T>& v) { /∗ ... ∗/ }template<> void sort<char*>(Array<char*>&) ;Given these declarations, stream<char> will be used as the definition of streams of chars; other streams willbe handled by class template specializations instantiated from the class template. Similarly, sort<char*>will be used as the sort function for arguments of type Array<char*>; other Array types will be sorted byfunctions generated from the template.
— end example ]2An explicit specialization shall be declared in a namespace enclosing the specialized template. An explicitspecialization whose declarator-id is not qualified shall be declared in the nearest enclosing namespace ofthe template, or, if the namespace is inline (7.3.1), any namespace from its enclosing namespace set. Such adeclaration may also be a definition. If the declaration is not a definition, the specialization may be definedlater (7.3.1.2).3A declaration of a function template or class template being explicitly specialized shall precede the declarationof the explicit specialization.
[ Note: A declaration, but not a definition of the template is required. — endnote ] The definition of a class or class template shall precede the declaration of an explicit specialization fora member template of the class or class template. [ Example:§ 14.7.3© ISO/IEC 2011 – All rights reserved373ISO/IEC 14882:2011(E)template<> class X<int> { /∗ ... ∗/ };// error: X not a templatetemplate<class T> class X;template<> class X<char*> { /∗ ... ∗/ };// OK: X is a template— end example ]4A member function, a member function template, a member class, a member enumeration, a member classtemplate, or a static data member of a class template may be explicitly specialized for a class specializationthat is implicitly instantiated; in this case, the definition of the class template shall precede the explicitspecialization for the member of the class template.
If such an explicit specialization for the member of aclass template names an implicitly-declared special member function (Clause 12), the program is ill-formed.5A member of an explicitly specialized class is not implicitly instantiated from the member declaration of theclass template; instead, the member of the class template specialization shall itself be explicitly defined if itsdefinition is required. In this case, the definition of the class template explicit specialization shall be in scopeat the point at which the member is defined.
The definition of an explicitly specialized class is unrelatedto the definition of a generated specialization. That is, its members need not have the same names, types,etc. as the members of a generated specialization. Members of an explicitly specialized class template aredefined in the same manner as members of normal classes, and not using the template<> syntax. The sameis true when defining a member of an explicitly specialized member class. However, template<> is used indefining a member of an explicitly specialized member class template that is specialized as a class template.[ Example:template<class T> struct A {struct B { };template<class U> struct C { };};template<> struct A<int> {void f(int);};void h() {A<int> a;a.f(16);}// A<int>::f must be defined somewhere// template<> not used for a member of an// explicitly specialized class templatevoid A<int>::f(int) { /∗ ...
∗/ }template<> struct A<char>::B {void f();};// template<> also not used when defining a member of// an explicitly specialized member classvoid A<char>::B::f() { /∗ ... ∗/ }template<> template<class U> struct A<char>::C {void f();};// template<> is used when defining a member of an explicitly// specialized member class template specialized as a class template§ 14.7.3374© ISO/IEC 2011 – All rights reservedISO/IEC 14882:2011(E)template<>template<class U> void A<char>::C<U>::f() { /∗ ...
∗/ }template<> struct A<short>::B {void f();};template<> void A<short>::B::f() { /∗ ... ∗/ }// error: template<> not permittedtemplate<> template<class U> struct A<short>::C {void f();};template<class U> void A<short>::C<U>::f() { /∗ ... ∗/ }// error: template<> required— end example ]6If a template, a member template or a member of a class template is explicitly specialized then that specialization shall be declared before the first use of that specialization that would cause an implicit instantiationto take place, in every translation unit in which such a use occurs; no diagnostic is required.
If the programdoes not provide a definition for an explicit specialization and either<b>Текст обрезан, так как является слишком большим</b>.