Topic: is_pointer<T> gives wrong answer for pointers to member variables
Author: google@vandevoorde.com (Daveed Vandevoorde)
Date: Thu, 8 May 2003 18:57:27 +0000 (UTC) Raw View
notbob@tessellation.com (Robert Allan Schwartz) wrote:
>
> template <typename T>
> class is_pointer { public: static const bool value = false; };
>
> template <typename T>
> class is_pointer<T *> { public: static const bool value = true; };
>
> #include <iostream>
>
> class i_am_a_class { };
>
> int main()
> {
> std::cout << "is_pointer<int i_am_a_class::* >::value = " <<
> is_pointer<int i_am_a_class::* >::value << std::endl;
> std::cout << "is_pointer<int (i_am_a_class::*)(void)>::value = " <<
> is_pointer<int (i_am_a_class::*)(void)>::value << std::endl;
>
> return 0;
> }
>
> gives the results:
>
> is_pointer<int i_am_a_class::* >::value = 1
> is_pointer<int (i_am_a_class::*)(void)>::value = 0
>
> on g++ v3.2, but gives the results:
>
> is_pointer<int i_am_a_class::* >::value = 0
> is_pointer<int (i_am_a_class::*)(void)>::value = 0
>
> on metrowerks v7.
>
> I believe the answers should all be 1.
>
> What does the standard say?
It should all be zero. Both types you're
passing are pointers-to-members; which are
not pointers (see 3.9.2/1).
Daveed
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]