在C++ 03中,如何确定类型T是否可解除引用?
我的意思是,我如何静态地确定是否*t是t类型的有效表达式T?
我的尝试:
template<bool B, class T = void> struct enable_if { };
template<class T> struct enable_if<true, T> { typedef T type; };
unsigned char (&helper(void const *))[2];
template<class T>
typename enable_if<
!!sizeof(**static_cast<T *>(NULL)),
unsigned char
>::type helper(T *);
template<class T>
struct is_dereferenceable
{ static bool const value = sizeof(helper(static_cast<T *>(NULL))) == 1; };
struct Test
{
int *operator *();
void operator *() const;
private:
Test(Test const &);
}; …Run Code Online (Sandbox Code Playgroud)