35 lines
1.4 KiB
Markdown
35 lines
1.4 KiB
Markdown
[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*]
|