Init
This commit is contained in:
49
cppdraft/temp/fct/general.md
Normal file
49
cppdraft/temp/fct/general.md
Normal file
@@ -0,0 +1,49 @@
|
||||
[temp.fct.general]
|
||||
|
||||
# 13 Templates [[temp]](./#temp)
|
||||
|
||||
## 13.7 Template declarations [[temp.decls]](temp.decls#temp.fct.general)
|
||||
|
||||
### 13.7.7 Function templates [[temp.fct]](temp.fct#general)
|
||||
|
||||
#### 13.7.7.1 General [temp.fct.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4052)
|
||||
|
||||
A function template defines an unbounded set of related functions[.](#1.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
A family of sort functions can be declared like this:template<class T> class Array { };template<class T> void sort(Array<T>&);
|
||||
|
||||
â *end example*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L4062)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
A function template can have the same name as other function templates
|
||||
and non-template functions ([[dcl.fct]](dcl.fct "9.3.4.6 Functions")) in the same scope[.](#2.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
A non-template function is not
|
||||
related to a function template
|
||||
(i.e., it is never considered to be a specialization),
|
||||
even if it has the same name and type
|
||||
as a potentially generated function template specialization[.](#2.sentence-2)[115](#footnote-115 "That is, declarations of non-template functions do not merely guide overload resolution of function template specializations with the same name. If such a non-template function is odr-used ([term.odr.use]) in a program, it must be defined; it will not be implicitly instantiated using the function template definition.")
|
||||
|
||||
[115)](#footnote-115)[115)](#footnoteref-115)
|
||||
|
||||
That is,
|
||||
declarations of non-template functions do not merely guide
|
||||
overload resolution of
|
||||
function template specializations
|
||||
with the same name[.](#footnote-115.sentence-1)
|
||||
|
||||
If such a non-template function is odr-used ([[basic.def.odr]](basic.def.odr#term.odr.use "6.3 One-definition rule")) in a program, it must be defined;
|
||||
it will not be implicitly instantiated using the function template definition[.](#footnote-115.sentence-2)
|
||||
1750
cppdraft/temp/fct/spec.md
Normal file
1750
cppdraft/temp/fct/spec.md
Normal file
File diff suppressed because it is too large
Load Diff
34
cppdraft/temp/fct/spec/general.md
Normal file
34
cppdraft/temp/fct/spec/general.md
Normal file
@@ -0,0 +1,34 @@
|
||||
[temp.fct.spec.general]
|
||||
|
||||
# 13 Templates [[temp]](./#temp)
|
||||
|
||||
## 13.10 Function template specializations [[temp.fct.spec]](temp.fct.spec#general)
|
||||
|
||||
### 13.10.1 General [temp.fct.spec.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L7526)
|
||||
|
||||
A function instantiated from a function template is called a function template
|
||||
specialization; so is an explicit specialization of a function template[.](#1.sentence-1)
|
||||
|
||||
Template arguments can be explicitly specified when naming the function
|
||||
template specialization, deduced from the context (e.g.,
|
||||
deduced from the function arguments in a call to the function template
|
||||
specialization, see [[temp.deduct]](temp.deduct "13.10.3 Template argument deduction")), or obtained from default template arguments[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/templates.tex#L7535)
|
||||
|
||||
Each function template specialization instantiated from a template
|
||||
has its own copy of any static variable[.](#2.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*: template<class T> void f(T* p) {static T s;};
|
||||
|
||||
void g(int a, char* b) { f(&a); // calls f<int>(int*) f(&b); // calls f<char*>(char**)}
|
||||
|
||||
Heref<int>(int*) has a static variables of typeint andf<char*>(char**) has a static variables of typechar*[.](#2.sentence-2)
|
||||
|
||||
â *end example*]
|
||||
Reference in New Issue
Block a user