[ Web Proxy ]
URL:
Viewing: https://fr.cppreference.com/cpp/language/function_template [Back]  [Original]

Function template cppreference.com
cppreference.com
Espaces de noms
Variantes

Function template

De cppreference.com

<metanoindex/>

 
 
Langage C++
Sujets gnraux
Contrle de flux
Instructions conditionnelles
Instructions d'itration
Instructions de saut
Fonctions
dclaration de fonction
expression lambda
fonction gnrique
spcificateur inline
spcification d'exception (obsolte)
spcificateur noexcept (C++11)
Exceptions
Espaces de noms
Types
spcificateur decltype (C++11)
Qualificatifs
qualificatifs const et volatile
qualificatifs de stockage
qualificatif constexpr (C++11)
qualificatif auto (C++11)
qualificatif alignas (C++11)
Initialisation
Littraux
Expressions
oprateurs alternatifs
Utilitaires
Types
dclaration typedef
dclaration d'alias de type (C++11)
attributs (C++11)
Jette
Original:
Casts
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
conversions implicites
conversion const_cast
conversion static_cast
conversion dynamic_cast
conversion reinterpret_cast
conversions style C et style fonction
Allocation de mmoire
Classes
Qualificatifs spcifiques aux membres de classe
Fonctions membres spciales
Modles
classes gnriques
fonctions gnriques
spcialisation de modles
paquets de paramtres (C++11)
Divers
Assembleur
 

Description

Des modles de conception permettent fonction gnrique qui fonctionnent sur diffrents types, sans la ncessit de rcrire 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.

Syntaxe

Dclaration

template < template_arguments > function_declaration (1)
export template < template_arguments > function_declaration (2) (avant C++11)
# Modle de dclaration de fonction Erreur de rfrence: Balise fermante </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.
# Exports dclaration de fonction template. Le corps de la fonction peut tre dfinie dans un fichier spar Erreur de rfrence: Balise fermante </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.

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)

1-2)

l'intrieur de la fonction identifier peut tre utilis comme un type
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.

3)

l'intrieur de la fonction identifier peut tre utilis comme une constante
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.

4-6)

Les arguments par dfaut
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.

Spcialisation

template <> ret function_name < template_args > ( func_args ) body
Spcialisation modifie la mise en uvre de la fonction de modle pour les paramtres des modles spcifiques
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.

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 dclaration de modle (avec le template_args donn) la coule 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.
Arguments template # implicites, dduites des arguments de la fonction. Aucune ambigut ne peut tre prsent
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.

Exemple

[edit]
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
}


Voir aussi

Notes

Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Web Proxy Viewer  |  New URL  |  Original Page