在一个类中,我有两种不同的方法,根据调用者模板参数应该是相互排斥的。C++ 03:相互排斥的方法,由于enable_if
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()
{ }
}
这不会编译。
error: type/value mismatch at argument 1 in template parameter list for 'template struct boost::enable_if' error: expected a type, got '! boost::is_same::value'
也许你想'boost :: enable_if_c'?见例如[Boost enable_if参考](http://www.boost.org/doc/libs/1_64_0/libs/core/doc/html/core/enable_if.html)。 –
为什么不能使用'disable_if' – danielspaniol
奇怪,为什么在'doSomething()'之前指定'const T&',因为返回类型应该已经由'typename boost :: enable_if ...'指定了? – Alexey