我想实现is_pointer.我想要这样的东西:
template <typename T >
bool is_pointer( T t )
{
// implementation
} // return true or false
int a;
char *c;
SomeClass sc;
someAnotherClass *sac;
is_pointer( a ); // return false
is_pointer( c ); // return true
is_pointer( sc ); // return false
is_pointer( sac ); // return true
Run Code Online (Sandbox Code Playgroud)
我该如何实现它?谢谢
我有这段代码:
template <typename T, typename R>
struct is_dereferenceable_exact
{
typedef char yes;
typedef struct { char dummy[2]; } no;
template <typename U, R (U::*)() const>
struct SFINAE;
template <typename U>
static yes test(SFINAE<U, &U::operator*>*);
template <typename U>
static no test(...);
static const bool value = sizeof(test<T>(0)) == sizeof(yes);
};
Run Code Online (Sandbox Code Playgroud)
此结构用于检查给定类型是否可解除引用,并且取消引用的结果具有类型 R.我使用省略号的旧方法,而sizeof不是void_t或故意检测成语 - 我想只使用C++ - 03特征(如果可能的话).
但我只是不能写出类似的结构,它只能确定是否存在T::operator*忽略它的类型.你能帮助我吗?
UPD我可以概括一下我的问题:如果我可以使用返回类型编写一些特征,我可以像上面的引子一样消除它们吗?