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. |
Inspecciona el tipo declarado de una entidad o consulta el tipo de retorno de una expresión .
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.
Contenido |
[editar] Sintaxis
decltype ( entity )
|
(1) | (ya que C + +11) | |||||||
decltype ( expression )
|
(2) | (ya que C + +11) | |||||||
[editar] Explicación
1)
Si el argumento es el nombre unparenthesised de un objeto / función, o es una expresión de acceso a miembros (o
object.member pointer->member), entonces el decltype especifica el tipo declarado de la entity especificado por esta expresión .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 el argumento es cualquier otra expresión de
T tipo, entoncesOriginal:
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 el valor de categoría de expression es' xValue, entonces el decltype especifica
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 categoría de valor de expression es' lvalue, entonces el decltype especifica
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)
de lo contrario, decltype especifica
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.
Tenga en cuenta que si el nombre de un objeto se parenthesised, se convierte en una expresión de valor-, con lo que decltype(arg) y decltype((arg)) son a menudo diferentes tipos .
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 es útil cuando se declara los tipos que son difíciles o imposibles de declarar usando la notación estándar, como lambda relacionados con tipos o tipos que dependen de los parámetros de plantilla .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.
[editar] Palabras clave
[editar] Ejemplo
#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'; }
Output:
i = 33, j = 66 i = 4, j = 9
[editar] Ver también
| (C++11) |
obtiene el tipo de expresión en el contexto no evaluada 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. (función de plantilla) |