This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: type_info::__is_pointer_p() not working?
- To: Carlo Wood <carlo at alinoe dot com>, gcc at gcc dot gnu dot org
- Subject: Re: type_info::__is_pointer_p() not working?
- From: Doug Gregor <gregod at cs dot rpi dot edu>
- Date: Sat, 28 Apr 2001 22:48:54 -0400
- References: <20010429042121.A24108@alinoe.com>
- Reply-To: gregod at cs dot rpi dot edu
On Saturday 28 April 2001 10:21, Carlo Wood wrote:
> Shouldn't this work?
>
> -------------------------------------------
> #include <iostream>
> #include <typeinfo>
>
> int main(void)
> {
> if (typeid(int*).__is_pointer_p())
> std::cout << "int* is a pointer.\n";
> else
> std::cout << "int* is not a pointer?!\n";
>
> return 0;
> }
> -------------------------------------------
>
> >g++-3.0 pointer.cc
> >a.out
>
> int* is not a pointer?!
>
> If it shouldn't work, then how CAN I check if a
> template parameter is a pointer or not? I used
> to use some overload trick, but recently 3.0 was
> changed to refuse my trick (before it only failed
> with -pendantic).
Partial specialization:
template<typename T> struct is_pointer { enum { value = 0 }; };
template<typename T> struct is_pointer<T*> { enum {value = 1 }; };
Then you can check with: is_pointer<int*>::value.