不确定这次我是否在模板编程方面走得太远了。我尝试传递模板模板参数。这个问题来自一个真实的问题,但我现在会以不同的方式解决这个问题。所以这个问题或多或少是“学术性的”
首先,我尝试将 F_
“存储”在将用作模板参数的结构中:
template <class M_, template <class> class F_>
struct Conf{
using F = F_; // Problem 1: F_ is not a type!
using M = M_;
};
然后从结构中读取 F
并用于实例化 func
:
template <class CONF> // CONF is a Conf<x, y>
void call(){
using F = typename CONF::F; // Problem 2: F_ is still not a type!
func<F>();
}
功能是:
template <template <class> F>
void func(){
F<MyType>::call();
}
问题是:我无法使用 using 来“存储”F
。我该怎么做才能在结构中传递 F
?
最佳答案
您应该像这样模板化您的using
:
template <class M_, template <class> class F_>
struct Conf{
template <class T>
using F = F_<T>;
using M = M_;
};
关于c++ - "using"为 "<template <class> class T>",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31500874/