【发布时间】:2014-07-21 01:19:36
【问题描述】:
我引用了一个模板类将其放入 mpl::vector 中:
boost::mpl::vector<int, boost::mpl::quote2<std::pair>>
然后,我得到了这样的第二个元素:
using A=typename boost::mpl::at<T, boost::mpl::int_<2>>::type;
我现在需要将原始模板类传递给这样的类:
template<class A, template<class, class> class C>
class B{
C<A, B*> _c;
};
我尝试使用apply或bind,但找不到让B接受第二个参数的方法。
我遇到了这样的错误:
error: template argument for template template parameter must be a class template or type alias template
编辑:
示例代码:
#include <boost/mpl/vector.hpp>
#include <boost/mpl/quote.hpp>
#include <boost/mpl/at.hpp>
template<class, class> class A{};
template<class A, template<class, class> class C>
class B{
C<A, B*> _c;
};
using T=boost::mpl::vector<int, boost::mpl::quote2<A>> ;
using T1=typename boost::mpl::at<T, boost::mpl::int_<0>>::type;
using T2=typename boost::mpl::at<T, boost::mpl::int_<1>>::type;
int main(){
B<T1, T2> b;
return 0;
}
我明白了:
error: template argument for template template parameter must be a class template or type alias template B<T1, T2> b;
【问题讨论】:
-
template class C > 应该只是 template
-
不,实际上这是有效的。意思是您期望一个具有 2 个模板参数的模板类。不工作的代码是使用 mpl 进行引用的代码,我试图在之后取消引用。
-
一个类模板,而不是一个模板类——这是辨别因素。 ;-]
-
请发布一个最小且完整的示例来显示您的问题。此外,MPL 向量是 0 索引的,因此向量的第二个元素将是
mpl::at<V, mpl::int_<1>>::type而不是mpl::at<V, mpl::int_<2>>::type。 -
哦,对不起2,因为我的代码有3个参数,它想简化,忘了把2改成1。现在写一个完整的例子。
标签: c++ templates c++11 boost boost-mpl