質問編集履歴
2
あ
test
CHANGED
File without changes
|
test
CHANGED
@@ -116,6 +116,60 @@
|
|
116
116
|
|
117
117
|
|
118
118
|
|
119
|
+
---
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
**欲を言えば**```class A```に変更を加えずに取得したいです
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
```cpp
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
template <std::size_t N, typename Class, typename Return, typename ... Args>
|
132
|
+
|
133
|
+
constexpr auto getArgType(Return(Class::*)(Args...)) {
|
134
|
+
|
135
|
+
return std::tuple_element_t<N, std::tuple<Args...>>();
|
136
|
+
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
//class Aの記述はこのままに
|
142
|
+
|
143
|
+
struct A {
|
144
|
+
|
145
|
+
A(int) {}
|
146
|
+
|
147
|
+
void hoge(int) {}
|
148
|
+
|
149
|
+
};
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
int main() {
|
154
|
+
|
155
|
+
//ここで型を取得する処理
|
156
|
+
|
157
|
+
using ArgType = decltype(getArgType<0>(&A::A));
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
std::cout << typeid(ArgType).name();
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
```
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
119
173
|
## 環境
|
120
174
|
|
121
175
|
c++20
|
1
a
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
-
std::cout << typeid(ArgType).name();
|
45
|
+
std::cout << typeid(ArgType).name();//出力 int
|
46
46
|
|
47
47
|
}
|
48
48
|
|