Function template
De cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Sommaire |
[modifier] Description
Des modèles de conception permettent fonction générique qui fonctionnent sur différents types, sans la nécessité de réécrire plusieurs fois
Original:
Templates allow generic function design that work on various types, without the need of rewriting it multiple times
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Syntaxe
[modifier] Déclaration
template < template_arguments > function_declaration
|
(1) | ||||||||
export template < template_arguments > function_declaration
|
(2) | (avant C++11) | |||||||
# Modèle de déclaration de fonction Erreur de référence : Clôture
</ref>
manquante pour la balise <ref>
.Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
# Exportés déclaration de fonction template. Le corps de la fonction peut être définie dans un fichier séparé Erreur de référence : Clôture
</ref>
manquante pour la balise <ref>
.Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Arguments
class identifier | (1) | ||||||||
typename identifier | (2) | ||||||||
integral_type identifier | (3) | ||||||||
class identifier = type_name
|
(4) | (depuis C++11) | |||||||
typename identifier = type_name
|
(5) | (depuis C++11) | |||||||
integral_type identifier = const_expr
|
(6) | (depuis C++11) | |||||||
À l'intérieur de la fonction identifier peut être utilisé comme un type
3) Original:
Inside the function identifier can be used as a type
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
À l'intérieur de la fonction identifier peut être utilisé comme une constante
4-6) Original:
Inside the function identifier can be used as a constant
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Les arguments par défaut
Original:
Default arguments
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Spécialisation
This section is incomplete Reason: partial specialization |
template <> ret function_name < template_args > ( func_args ) body
|
|||||||||
Spécialisation modifie la mise en œuvre de la fonction de modèle pour les paramètres des modèles spécifiques
Original:
Specialization changes the implementation of the template function for specific template parameters
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Appel
function_name < template_args > ( func_args )
|
(1) | ||||||||
function_name ( unambiguous_func_args )
|
(2) | ||||||||
Arguments template # explicites, si func_args ne correspondent pas parfaitement avec les types comme dans la déclaration de modèle (avec le template_args donné) la coulée d'habitude va se produire
Original:
# Explicit template arguments, if func_args don't match perfectly with the types as in the template declaration (with the given template_args) the usual casting will occur
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Arguments template # implicites, déduites des arguments de la fonction. Aucune ambiguïté ne peut être présent
Original:
# Implicit template arguments, deduced from the function arguments. No ambiguity can be present
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
This section is incomplete Reason: better explanation/example |
[modifier] Exemple
This section is incomplete |
template<typename T> struct S { template<typename U> void foo(){} }; template<typename T> void bar() { S<T>s; s.foo<T>(); // error: < parsed as less than operator s.template foo<T>(); // OK }
[modifier] Voir aussi
[modifier] Notes
Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.