我需要将一个有两个参数的模板改为只有一个参数的模板。
我想要绑定模板的第一个参数:
template<class T1, class T2>
struct Two_Parameter_Template {
// Two ctor's
Two_Parameter_Template() { };
template<class Param>
Two_Parameter_Template(Param) { /* ... */ }
};
通过使用另一种(非侵入式)模板机制:
//bind the first parameter of a template "bound", this template should work as
//an adapter reducing the number of parameters required
template<class X, template<class, class> class bound>
struct bind_1st {
template<class T> // this is the resulting one parameter template
struct eval {
eval () {
bound<X, T>();
}
template<class T2>
eval (T2 obj) {
bound<X, T>(obj);
}
};
};
为了以后可以将此模板用作另一个模板的参数,该模板少了一个自己的参数(类似下面的内容):
template <template<class> class One_Parameter_Template>
struct SomeTemplate {
//...
};
// Later in the code
typedef SomeTemplate<bind_1st<Bound_Param_class, Two_Parameter_Template> >::eval ConcreteClass;
问题是 - C++中是否有语法来支持这一点。
最好的问候, Marcin