decltype specifier
提供: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. |
エンティティの宣言された型を検査または式の戻り値の型を照会.
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.
目次 |
[編集] 構文
decltype ( entity )
|
(1) | (C + + 11以来) | |||||||
decltype ( expression )
|
(2) | (C + + 11以来) | |||||||
[編集] 説明
1)
引数がいずれかのオブジェクト/関数のunparenthesised名前であるか、またはメンバアクセス式(
object.memberまたはpointer->member)ならば、decltypeは、この式で指定されたentityの宣言された型を指定します.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)
引数がタイプ
Tの他の表現である場合Original:
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)
値カテゴリのexpressionである場合はxValue'は、その後、decltypeは
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)
expressionの値カテゴリがある場合左辺値はとすると、decltypeは
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)
そうでなければ、decltypeは
T指定しますOriginal:
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.
従って、オブジェクトの名前が括弧で括られている場合、それは左辺値式になることに注意してくださいdecltype(arg)とdecltype((arg))しばしば異なる種類があります.
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テンプレートパラメータに依存してラムダに関連するタイプまたは型と同様に、標準の表記法を使用して宣言することはほとんど不可能であり、型を宣言する場合に便利です.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.
[編集] キーワード
[編集] 例
#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
[編集] も参照してください
| (C++11) |
未評価のコンテキストで、式の型を取得します 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. (関数テンプレート) |