decltype specifier
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. |
<metanoindex/>
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.
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.
You can help to correct and verify the translation. Click here for instructions.
2)
Si l'argument est une autre expression de
T type, alorsOriginal:
If the argument is any other expression of type
T, thenThe 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.
a)
si le catgorie de valeur de expression est' xValue, le decltype spcifie
T&&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.
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.
You can help to correct and verify the translation. Click here for instructions.
c)
autrement, decltype spcifie
TOriginal:
otherwise, decltype specifies
TThe 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.
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.
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.
You can help to correct and verify the translation. Click here for instructions.
Mots-cls
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) |