【发布时间】:2016-06-17 18:00:58
【问题描述】:
我正在尝试了解 boost mpl,我想知道这样的事情是否可行。具体来说,是否可以根据模板参数有条件地对函数进行类型定义?类似于这个玩具示例的内容:
template<typename arg1, typename arg2, typename rtype>
rtype getValue()
{
typedef boost::conditional<
// typedef boost::mpl::if_<
boost::is_same<rtype, double>,
double multiply(double a, double b),
int multiply(int a, int b)
> function;
function test;
return test(arg1::value, arg2::value);
}
我尝试了上面的代码,得到了“模板参数2无效”的错误。所以我想知道是否有办法将函数定义转换为有效类型,因为它是有效的 typedef?
我也知道还有很多其他方法可以做到这一点。我不想解决问题,因为这是一种学习尝试。
【问题讨论】:
-
is_same后面不是少了一个逗号吗?
-
@lorro 我是,不幸的是我要编译的代码不是。