使用boost :: mpl :: if_进行编译错误

时间:2012-09-06 02:40:09

标签: c++ boost boost-mpl

我正在尝试使用boost :: mpl基于某些模板参数类型的常量来控制某些指针类型的常量。这是我的尝试:

template<typename T>
struct iter {
   typedef typename boost::mpl::if_<boost::is_same<T, const list>, const sexpr *, sexpr *>::type pointer;
};
然而,编译器拒绝这样的说法:

sexpr.h:154: error: ISO C++ forbids declaration of `type name' with no type
sexpr.h:154: error: template argument 2 is invalid
sexpr.h:154: error: template argument 1 is invalid
sexpr.h:154: error: `type' does not name a type

有什么迹象表明我做错了什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

我能够使用is_const修复它:

typedef typename boost::mpl::if_<boost::is_const<T>, const sexpr *, sexpr *>::type pointer;

谢谢!