回答編集履歴
2
コメントへの回答
test
CHANGED
@@ -77,3 +77,113 @@
|
|
77
77
|
```
|
78
78
|
|
79
79
|
[wandbox](https://wandbox.org/permlink/n8mQw23IGqPjZwJZ)
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
---
|
84
|
+
|
85
|
+
【コメントに対する回答】
|
86
|
+
|
87
|
+
print()を再帰定義してみました。
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
```C++
|
92
|
+
|
93
|
+
#include <iostream>
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
template<int... kArgs>
|
98
|
+
|
99
|
+
class Foo
|
100
|
+
|
101
|
+
{
|
102
|
+
|
103
|
+
template<typename...>
|
104
|
+
|
105
|
+
void printImpl()
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
template<int kFirst, int... kRest>
|
114
|
+
|
115
|
+
void printImpl()
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
std::cout << kFirst << " ";
|
120
|
+
|
121
|
+
printImpl<kRest...>();
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
public:
|
128
|
+
|
129
|
+
void print()
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
printImpl<kArgs...>();
|
134
|
+
|
135
|
+
std::cout << "\n";
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
Foo<(kArgs*2)...> map_double() const
|
140
|
+
|
141
|
+
{
|
142
|
+
|
143
|
+
return Foo<(kArgs*2)...>();
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
int main()
|
152
|
+
|
153
|
+
{
|
154
|
+
|
155
|
+
Foo<>().print();
|
156
|
+
|
157
|
+
Foo<1>().print();
|
158
|
+
|
159
|
+
Foo<1, 2>().print();
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
Foo<1, 2, 3>().print();
|
164
|
+
|
165
|
+
Foo<1, 2, 3>().map_double().print();
|
166
|
+
|
167
|
+
Foo<1, 2, 3>().map_double().map_double().print();
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
```
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
> template<typename...>
|
176
|
+
|
177
|
+
void printImpl()
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
にて再帰の最後でテンプレート引数が無くなった時、および、テンプレート実引数が0個の時(Foo<>)に対応してみました。「曖昧」にならないかちょっと心配ですが、gcc, clang, msvcで通りましたし、[MSDN](https://msdn.microsoft.com/ja-jp/library/zaycz069.aspx)のこの記述を見る限り使って良さそうです。
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
[wandbox](https://wandbox.org/permlink/FNtz7ccRgnKDeHCc)
|
1
余分なので削除
test
CHANGED
@@ -77,7 +77,3 @@
|
|
77
77
|
```
|
78
78
|
|
79
79
|
[wandbox](https://wandbox.org/permlink/n8mQw23IGqPjZwJZ)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
結構難易度の高い領域ですので、たいへんと思いますが頑張って下さい。
|