c++ - "using"为 "<template <class> class T>"

标签 c++ templates

不确定这次我是否在模板编程方面走得太远了。我尝试传递模板模板参数。这个问题来自一个真实的问题,但我现在会以不同的方式解决这个问题。所以这个问题或多或少是“学术性的”

首先,我尝试将 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/

相关文章:

c++ - CUDA 模板内核和纹理

c++ - 在模板中捕获异常类

c++ - 满足条件时如何在中间停止折叠表达式函数调用并返回该值?

c++ - 有什么方法可以从 C++ 中的成员指针类型派生对象类型

php - 当我安装 "Smarty"php 时,您需要锁定文件夹 templates 和 templates_r 以供公共(public)访问吗?

c++ - SetProgressValue() 在 ConEmu 中不起作用

c++ - 函数调用中创建的对象和传入的对象有什么区别

c++ - C++ CLI 是 C++ 的超集吗?

c++ - 如何链接到 Visual C++ 2010 中的 .lib 文件?没有引用项目?

来自服务器端的 C++ 套接字主机名