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

decltype specifier cppreference.com
cppreference.com
Espaces de noms
Variantes

decltype specifier

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
 
Inspecte le type dclar d'une entit ou interroge le type de retour d'une expression .
Original:
Inspects the declared type of an entity or queries the return type of an expression.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Syntaxe

decltype ( entity ) (1) (depuis C++11)
decltype ( expression ) (2) (depuis C++11)

Explication

1)
Si l'argument est soit le nom d'un objet unparenthesised / fonction ou une expression d'accs au membre (object.member ou pointer->member), puis le decltype spcifie le type dclar de la entity spcifi par cette expression .
Original:
If the argument is either the unparenthesised name of an object/function, or is a member access expression (object.member or pointer->member), then the decltype specifies the declared type of the entity specified by this expression.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
Si l'argument est une autre expression de T type, alors
Original:
If the argument is any other expression of type T, then
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
a)
si le catgorie de valeur de expression est' xValue, le decltype spcifie T&&
Original:
if the catgorie de valeur of expression is xvalue, then the decltype specifies T&&
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
b)
si la valeur de la catgorie expression est lvalue', le decltype spcifie T&
Original:
if the value category of expression is lvalue, then the decltype specifies T&
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
c)
autrement, decltype spcifie T
Original:
otherwise, decltype specifies T
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Notez que si le nom d'un objet est parenthesised, elle devient une expression lvalue, ce qui decltype(arg) et decltype((arg)) sont souvent diffrents types .
Original:
Note that if the name of an object is parenthesised, it becomes an lvalue expression, thus decltype(arg) and decltype((arg)) are often different types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
decltype est utile lors de la dclaration des types qui sont difficiles ou impossibles dclarer en utilisant la notation standard, comme lambda lis types ou des types qui dpendent des paramtres du modle .
Original:
decltype is useful when declaring types that are difficult or impossible to declare using standard notation, like lambda-related types or types that depend on template parameters.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Mots-cls

decltype

Exemple

#include <iostream>

struct A {
   double x;
};
const A* a = new A();

decltype( a->x ) x3;       // type of x3 is double (declared type)
decltype((a->x)) x4 = x3;  // type of x4 is const double& (lvalue expression)

template <class T, class U>
auto add(T t, U u) -> decltype(t + u); // return type depends on template parameters

int main() 
{
    int i = 33;
    decltype(i) j = i*2;
   
    std::cout << "i = " << i << ", "
              << "j = " << j << '\n';

    auto f = [](int a, int b) -> int {
       return a*b;
    };
   
    decltype(f) f2{f}; // the type of a lambda function is unique and unnamed
    i = f(2, 2);
    j = f2(3, 3);
   
    std::cout << "i = " << i << ", "
              << "j = " << j << '\n';
}

Rsultat :

i = 33, j = 66
i = 4, j = 9

Voir aussi

(C++11)
obtient le type d'expression dans un contexte non value
Original:
obtains the type of expression in unevaluated context
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(fonction gnrique) [edit]

Web Proxy Viewer  |  New URL  |  Original Page