【发布时间】:2017-06-19 07:21:48
【问题描述】:
在一个类中,我有两种不同的方法,它们应该是互斥的,具体取决于调用者模板参数。
class Foo
{
// For collections
template<class T>
typename boost::enable_if<boost::is_same<typename std::vector<typename T::value_type>, T>::value, const T&>::type
doSomething()
{ }
// For single types
template<class T>
typename boost::enable_if<!boost::is_same<typename std::vector<typename T::value_type>, T>::value, const T&>::type
doSomething()
{ }
}
这不会编译。
错误:'template struct boost::enable_if' 模板参数列表中参数 1 的类型/值不匹配 错误:需要一个类型,得到'! boost::is_same::value'
【问题讨论】:
-
也许你想要
boost::enable_if_c?参见例如the Boost enable_if reference. -
为什么不能使用
disable_if -
奇怪,为什么
doSomething()之前指定了const T&,返回类型应该已经被typename boost::enable_if...指定了? -
我认为您这里有语法错误?您已经指定了两次返回类型。
-
是的,正确的。我不需要返回类型两次,复制粘贴错误,我的坏
标签: c++ boost sfinae c++03 enable-if