【发布时间】:2014-12-09 15:18:24
【问题描述】:
我经常想要获取类模板参数的 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 的最佳解决方法是什么?
【问题讨论】:
-
它只是一个包含这些对象的向量,抱歉可以省略(或解释它)。关键是我使用 auto 是因为我实际上遍历了一个元组,然后遍历了向量 (fs),这就是为什么我真的想使用 auto 然后从中提取模板类型。
-
这个细节很关键。向量是同质的。