how to implement is_pointer?

后端 未结 4 1311
长情又很酷
长情又很酷 2020-12-31 19:09

I want to implement is_pointer. I want something like this:

template 
bool is_pointer( T t )
{
   // implementation
} // return true or fa         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-31 19:40

    template 
    bool is_pointer(T const &t) // edited: was "T t"; see the comments
    {
       return false;
    }
    
    template 
    bool is_pointer(T *t)
    {
       return true;
    }
    

    You might not believe it, but it works. The reason is that the most specific template implementation will be chosen, which is the one which takes the pointer type.

提交回复
热议问题