“using”for“ class T>”
问题描述:
不确定这次是否使用模板编程走远。我尝试传递一个模板模板参数。这个问题来自一个真正的问题,但我现在要以不同的方式解决这个问题。所以,问题是或多或少的“学院派”“using”for“<template <class> class T>”
首先,我尝试将被用来作为模板参数的结构“存储” 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>();
}
而且FUNC是:
template <template <class> F>
void func(){
F<MyType>::call();
}
问题是:我不能使用“存储”F
。我能做些什么来在结构中传递F
?
答
你应该模板您using
这样的:
template <class M_, template <class> class F_>
struct Conf{
template <class T>
using F = F_<T>;
using M = M_;
};
'F_'是一个模板类型。所以你需要写'使用F = F_'或其他东西。 –
CoffeeandCode