我经常想获得类模板参数的decltype,以便进一步使用它,比如在循环中。下面是我简化后的循环,展示了我的问题:
template <typename T>
class Foo {
public:
T type; //This is my hack to get decltype of T
};
template <typename T>
class Bar {
public:
};
int main() {
for(auto& foo : fs) {
//Is there some way to get the decltype of the template without having to refer to some arbitrary T member of Foo?
auto bar = someFunction<decltype(foo.type)>();
}
}
有没有一种方法可以在不使用这种hack的情况下获取模板参数的decltype?如果没有,有什么最好的解决方法来获取这样一个值的decltype?