遇到SFINAE问题.我需要能够确定Type是否具有成员函数operator->,无论其返回类型如何.示例如下.
这个类在测试者中.它定义了operator - >(),返回类型为X*.因此我不知道'X'到处硬编码是什么.
template <class X>
class PointerX
{
...
X* operator->() const;
...
}
Run Code Online (Sandbox Code Playgroud)
此类尝试确定传入的T是否具有方法operator-> defined; 无论operator-> return类型是什么.
template<typename T>
struct HasOperatorMemberAccessor
{
template <typename R, typename C> static R GetReturnType( R ( C::*)()const);
template<typename U, typename R, R(U::*)()const> struct SFINAE{};
template<typename U> static char Test(SFINAE<U, decltype( GetReturnType(&U::operator->)), &U::operator-> >*);
template<typename U> static uint Test(...);
static const bool value = sizeof(Test<T>(0)) == sizeof(char);
};
Run Code Online (Sandbox Code Playgroud)
除了operator-> return类型必须是'Object'之外,这个类与上面完全相同.
template<typename T>
struct HasOperatorMemberAccessorOBJECT
{
template <typename R, typename C> static R …Run Code Online (Sandbox Code Playgroud)