我目前正在尝试编译以下内容:
class foo {
};
class bar {
public:
const foo & to_foo() const {
return f;
}
foo & to_foo() {
return f;
}
private:
foo f;
};
template< typename T, typename Enable = void >
class convert {};
template< typename T >
struct convert< T, typename std::enable_if< std::is_member_function_pointer< decltype( &T::to_foo ) >::value >::type > {
static const foo & call1( const bar & b ) {
return b.to_foo();
}
static foo & call2( bar & b ) {
return b.to_foo();
}
};
然而,由于存在两个可能的to_foo()
成员,专业化变得混乱,因此它将选择默认情况。一旦我删除其中一个to_foo()
成员,它就会起作用,但是其中一种callX()
方法会失败,因为它与常量不匹配。
在这种情况下有什么方法可以检测到这个功能吗?
编辑:
这是关于 ideone 的示例:http: //ideone.com/E6saX
当其中一种方法被删除时,它工作得很好:http: //ideone.com/iBKoN