質問編集履歴

4

VS2019でも試したという旨を追記

2022/10/12 06:18

投稿

fana
fana

スコア11663

test CHANGED
File without changes
test CHANGED
@@ -38,6 +38,8 @@
38
38
  * (貧乏故,非常に古いPCの上で)Visual Studio 2017 を使用しています.プロジェクトのプロパティで「C++ 言語標準」という選択肢を「ISO C++17標準(/std:c++17)」にしてします.
39
39
  * 上記環境が悪いのか? と思い,paiza.io というサイトでもやってみましたが結果は同じでした.(なお,こちらのサイトでは言語選択肢が「C++」となっていて,C++のどの版として実行されているのかはわかりませんでした)
40
40
 
41
+ (その後,Visual Studio 2019 も試したところ, どうにも Visual Studio 2017 だけ挙動が異なるようであった → 自己回答の形で記述)
42
+
41
43
  ---
42
44
 
43
45
  [追記]

3

文言微修正

2022/10/07 08:02

投稿

fana
fana

スコア11663

test CHANGED
File without changes
test CHANGED
@@ -62,9 +62,13 @@
62
62
  > A structured binding declaration first introduces a uniquely-named variable (here denoted by e) to hold the value of the initializer, as follows:
63
63
  > ・ If expression has array type A and no ref-qualifier is present, then e has type cv A, where cv is the cv-qualifiers in the cv-auto sequence, and each element of e is copy- (for (1)) or direct- (for (2,3)) initialized from the corresponding element of expression.
64
64
 
65
- とのことで,配列の場合で且つ私の書き方
65
+ とのことで,今は配列の場合であって,且つ私の書き方は
66
+
67
+ > attr(optional) cv-auto ref-qualifier(optional) [ identifier-list ] = expression ; (1)
68
+
69
+ に相当すると思うので,
66
70
  `e` とは,私の配列の要素のコピーを持っている配列変数なのであって,この `e` の型とは `cv A` だそうです.
67
- `cv-auto sequence` というのを私は特に書いていないと思うので,つまり `e` の型たる `E` とはここでいうところの `array type A` かと.
71
+ `cv-auto sequence` というところに `cv` なるものを私は特に書いていないと思うので,つまり `e` の型たる `E` とはここでいうところの `array type A` かと.
68
72
 
69
73
  で,この `array type A` というのが,私の例では `const int[2]` だということ( `int[2]` ではなくて)…なのかと読みました.
70
74
  合っていますか?

2

調べたことを追記

2022/10/07 07:58

投稿

fana
fana

スコア11663

test CHANGED
File without changes
test CHANGED
@@ -38,3 +38,34 @@
38
38
  * (貧乏故,非常に古いPCの上で)Visual Studio 2017 を使用しています.プロジェクトのプロパティで「C++ 言語標準」という選択肢を「ISO C++17標準(/std:c++17)」にしてします.
39
39
  * 上記環境が悪いのか? と思い,paiza.io というサイトでもやってみましたが結果は同じでした.(なお,こちらのサイトでは言語選択肢が「C++」となっていて,C++のどの版として実行されているのかはわかりませんでした)
40
40
 
41
+ ---
42
+
43
+ [追記]
44
+ 今 [ココ](https://en.cppreference.com/w/cpp/language/structured_binding) を読んでいます.
45
+ 私には非常に読みづらく,解釈に難儀していますが,この質問の例(配列)については以下のような話なのでしょうか?
46
+
47
+ "Case 1: binding an array" のところに,
48
+
49
+ > Note that if the array type E is cv-qualified, so is its element type.
50
+
51
+ という記述があり,コレが関係しているように思えます.
52
+ (「E が const なら要素も const になるぞ」という話かと)
53
+
54
+ ここの `type E` とは何か? というのは,ちょっと上の方で
55
+
56
+ > We use E to denote the type of the expression e.
57
+
58
+ とのことです. `e` の型である,と.
59
+
60
+ そしたら `expression e` とは何か? というと,もうちょっと上の方で
61
+
62
+ > A structured binding declaration first introduces a uniquely-named variable (here denoted by e) to hold the value of the initializer, as follows:
63
+ > ・ If expression has array type A and no ref-qualifier is present, then e has type cv A, where cv is the cv-qualifiers in the cv-auto sequence, and each element of e is copy- (for (1)) or direct- (for (2,3)) initialized from the corresponding element of expression.
64
+
65
+ とのことで,配列の場合で且つ私の書き方では,
66
+ `e` とは,私の配列の要素のコピーを持っている配列変数なのであって,この `e` の型とは `cv A` だそうです.
67
+ `cv-auto sequence` というのを私は特に書いていないと思うので,つまり `e` の型たる `E` とはここでいうところの `array type A` かと.
68
+
69
+ で,この `array type A` というのが,私の例では `const int[2]` だということ( `int[2]` ではなくて)…なのかと読みました.
70
+ 合っていますか?
71
+

1

実験環境について追記

2022/10/07 01:58

投稿

fana
fana

スコア11663

test CHANGED
File without changes
test CHANGED
@@ -30,3 +30,11 @@
30
30
  }
31
31
  ```
32
32
 
33
+ ---
34
+
35
+ [追記]
36
+ 念のため,試している環境を示しておきます.
37
+
38
+ * (貧乏故,非常に古いPCの上で)Visual Studio 2017 を使用しています.プロジェクトのプロパティで「C++ 言語標準」という選択肢を「ISO C++17標準(/std:c++17)」にしてします.
39
+ * 上記環境が悪いのか? と思い,paiza.io というサイトでもやってみましたが結果は同じでした.(なお,こちらのサイトでは言語選択肢が「C++」となっていて,C++のどの版として実行されているのかはわかりませんでした)
40
+