回答編集履歴
2
refinement
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[C++11で導入された`decltype`](https://cpprefjp.github.io/lang/cpp11/decltype.html)は、2003年の [n1478](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1478.pdf) 初版から最終的に2007年の [n2343](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2343.pdf) (Revision 7)まで、長い期間
|
1
|
+
[C++11で導入された`decltype`](https://cpprefjp.github.io/lang/cpp11/decltype.html)は、2003年の [n1478](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1478.pdf) 初版から最終的に2007年の [n2343](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2343.pdf) (Revision 7)まで、長い期間議論された後に正式採用された言語機能だったようです。
|
2
2
|
|
3
3
|
[n2115](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2115.pdf) (Revision 6) によれば、「変数名に対してはソースコード上で宣言している型」を直接探し出しますが、「ソースコードに登場しない式では左辺値(lvalue)は参照型とする」とあります。
|
4
4
|
|
@@ -20,7 +20,7 @@
|
|
20
20
|
|
21
21
|
----
|
22
22
|
|
23
|
-
変数`a`に対して`decltype(a)`と`decltype((a))`をどのように扱うかについては、議論を重ねる中で変遷があったようです。
|
23
|
+
変数`a`に対して`decltype(a)`と`decltype((a))`をどのように扱うかについては、C++11での正式採用に向けて議論を重ねる中でも変遷があったようです。
|
24
24
|
- 2004年 [n1705](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1705.pdf) (Revision 4)では「`decltype((e))`は`decltype(e)`と同じと明記する」
|
25
25
|
- 2006年 [n2115](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2115.pdf) (Revision 6)では「`decltype((e))`と`decltype(e)`は別扱いとする」
|
26
26
|
- 最終的に「`decltype((e))`と`decltype(e)`は別扱い」のまま決着したようです。
|
1
update
answer
CHANGED
@@ -3,14 +3,10 @@
|
|
3
3
|
[n2115](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2115.pdf) (Revision 6) によれば、「変数名に対してはソースコード上で宣言している型」を直接探し出しますが、「ソースコードに登場しない式では左辺値(lvalue)は参照型とする」とあります。
|
4
4
|
|
5
5
|
> 2.2 Semantics of `decltype`
|
6
|
-
> Determining the type `decltype(e)` build on a single guiding principle: **look for the declared type of the expression `e`.** If `e` is a variable or formal parameter, or a function/operator invocation, the programmer can trace down the variable's, parameter's, or function's declaration, and **find the type declared for the particular entity directly from the program text**. This type is the result of `decltype`. For expressions that do not have a declaration in the program text, such as literals and calls to built-in operators, lvalueness implies a reference type.
|
6
|
+
> Determining the type `decltype(e)` build on a single guiding principle: **look for the declared type of the expression `e`.** If `e` is a variable or formal parameter, or a function/operator invocation, the programmer can trace down the variable's, parameter's, or function's declaration, and **find the type declared for the particular entity directly from the program text**. This type is the result of `decltype`. **For expressions that do not have a declaration in the program text, such as literals and calls to built-in operators, lvalueness implies a reference type**.
|
7
7
|
|
8
|
-
変数`a`に対して`decltype(a)`と`decltype((a))`をどのように扱うかについては、議論を重ねる中で変遷があったようです。
|
9
|
-
- 2004年 [n1705](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1705.pdf) (Revision 4)では「`decltype((e))`は`decltype(e)`と同じと明記する」
|
10
|
-
- 2006年 [n2115](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2115.pdf)(Revision 6)では「`decltype((e))`と`decltype(e)`は別扱いとする」
|
11
|
-
|
8
|
+
この考え方を質問中コードに適用すると、次の通りとなります。
|
12
9
|
|
13
|
-
----
|
14
10
|
```c++
|
15
11
|
int a = 2;
|
16
12
|
|
@@ -19,4 +15,12 @@
|
|
19
15
|
|
20
16
|
decltype((a)) c = a;
|
21
17
|
// 式(a) の宣言はソースコードに出現しない → int&
|
22
|
-
```
|
18
|
+
```
|
19
|
+
|
20
|
+
|
21
|
+
----
|
22
|
+
|
23
|
+
変数`a`に対して`decltype(a)`と`decltype((a))`をどのように扱うかについては、議論を重ねる中で変遷があったようです。
|
24
|
+
- 2004年 [n1705](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1705.pdf) (Revision 4)では「`decltype((e))`は`decltype(e)`と同じと明記する」
|
25
|
+
- 2006年 [n2115](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2115.pdf) (Revision 6)では「`decltype((e))`と`decltype(e)`は別扱いとする」
|
26
|
+
- 最終的に「`decltype((e))`と`decltype(e)`は別扱い」のまま決着したようです。
|