回答編集履歴
4
完全コードで型の違いがわかりにくいので、値をそれぞれ区別できるように修正
answer
CHANGED
@@ -48,7 +48,6 @@
|
|
48
48
|
#include <tuple>
|
49
49
|
#include <vector>
|
50
50
|
#include <type_traits>
|
51
|
-
#include <boost/type_index.hpp>
|
52
51
|
|
53
52
|
template <class Tuple, class Elem, std::size_t ...Indices>
|
54
53
|
void emplace_helper(Tuple& tup, Elem&& elem, std::index_sequence<Indices...>) {
|
@@ -65,20 +64,29 @@
|
|
65
64
|
return res;
|
66
65
|
}
|
67
66
|
#include <iostream>
|
67
|
+
#include <string>
|
68
|
+
|
68
69
|
int main() {
|
69
|
-
std::vector<std::tuple<int, double, std::string>> source{
|
70
|
+
std::vector<std::tuple<int, double, std::string>> source{
|
71
|
+
{1, 1.1, "one"},
|
72
|
+
{2, 2.2, "two"}
|
73
|
+
};
|
74
|
+
|
70
|
-
|
75
|
+
auto [int_vec, double_vec, string_vec] = vt_to_tv(source);
|
76
|
+
|
71
|
-
|
77
|
+
for (auto&& elem : int_vec)
|
72
|
-
|
78
|
+
{ std::cout << elem << " "; }
|
73
79
|
std::cout << "\n";
|
80
|
+
for (auto&& elem : double_vec)
|
74
|
-
|
81
|
+
{ std::cout << elem << " "; }
|
75
82
|
std::cout << "\n";
|
83
|
+
for (auto&& elem : string_vec)
|
76
|
-
|
84
|
+
{ std::cout << elem << " "; }
|
77
85
|
std::cout << "\n";
|
78
86
|
// 1 2
|
79
|
-
// 1 2
|
87
|
+
// 1.1 2.2
|
80
|
-
//
|
88
|
+
// one two
|
81
89
|
}
|
82
90
|
```
|
83
91
|
|
84
|
-
[Wandboxで実行する](https://wandbox.org/permlink/
|
92
|
+
[Wandboxで実行する](https://wandbox.org/permlink/XeJyQJWM5HTPaVAW)
|
3
コピペのopが残っていたので `,` に
answer
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
すると、次のように(この場合は左結合の)カンマ区切りの式を得ることができます。
|
34
34
|
|
35
35
|
```
|
36
|
-
((push_0 , push_1) , ...)
|
36
|
+
((push_0 , push_1) , ...) , push_N-1
|
37
37
|
```
|
38
38
|
|
39
39
|
ここで `push_N` は
|
2
fold expressionの説明で結合方向を解説していないので修正
answer
CHANGED
@@ -30,16 +30,17 @@
|
|
30
30
|
}
|
31
31
|
```
|
32
32
|
|
33
|
-
すると、次のようにカンマ区切りの式を得ることができます。
|
33
|
+
すると、次のように(この場合は左結合の)カンマ区切りの式を得ることができます。
|
34
34
|
|
35
|
-
```cpp
|
36
|
-
get<0>(tup).push_back(get<0>(elem)),
|
37
|
-
get<1>(tup).push_back(get<1>(elem)).
|
38
|
-
get<2>(tup).push_back(get<2>(elem)),
|
39
|
-
...,
|
40
|
-
get<N-1>(tup).push_back(get<N-1>(elem))
|
41
35
|
```
|
36
|
+
((push_0 , push_1) , ...) op push_N-1
|
37
|
+
```
|
42
38
|
|
39
|
+
ここで `push_N` は
|
40
|
+
`std::get<N>(tup).emplace_back(std::get<N>(elem))`
|
41
|
+
のことです
|
42
|
+
|
43
|
+
|
43
44
|
完全なコードを載せておきます。
|
44
45
|
|
45
46
|
|
1
`get<N-1>(res).push_back(get<2>(v[i]));` => `get<N-1>(res).push_back(get<N-1>(v[i]));`
answer
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
get<1>(res).push_back(get<1>(v[i]));
|
10
10
|
get<2>(res).push_back(get<2>(v[i]));
|
11
11
|
...
|
12
|
-
get<N-1>(res).push_back(get<
|
12
|
+
get<N-1>(res).push_back(get<N-1>(v[i]));
|
13
13
|
```
|
14
14
|
|
15
15
|
をどうやって展開するかです。
|
@@ -37,7 +37,7 @@
|
|
37
37
|
get<1>(tup).push_back(get<1>(elem)).
|
38
38
|
get<2>(tup).push_back(get<2>(elem)),
|
39
39
|
...,
|
40
|
-
get<N-1>(tup).push_back(get<
|
40
|
+
get<N-1>(tup).push_back(get<N-1>(elem))
|
41
41
|
```
|
42
42
|
|
43
43
|
完全なコードを載せておきます。
|