C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

typetraits fail on pointer to member function?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Ralph Zhang
Guest





PostPosted: Wed Dec 22, 2004 8:51 am    Post subject: typetraits fail on pointer to member function? Reply with quote



Hi,

I am reading Modern C++ Design and it mentions typetraits of pointer to
member function, so I write the following program to test that:

-------------------------------------------------------------------------------
#include <iostream>
template <typename T>
class TypeTraits
{
private:
template <class U> struct PtoMTraits
{
enum {result = false};
};

template <class U, class V> struct PtoMTraits<U V::*>
{
enum {result = true};
};

public:
static const bool isPtoM = PtoMTraits<T>::result;
};

struct Empty
{
int MemFun(int){return 0;}
};

int main()
{
typedef int(Empty::*PtoMType)(int);
PtoMType pTomf = &Empty::MemFun;

bool isPtoM = TypeTraits<PtoMType>::isPtoM;
std::cout << "is a pointer to member function: " << isPtoM <<
std::endl;
}
-------------------------------------------------------------------------------
It compiles both on VC7.1 and g++ 3.3.3(cygwin), but the VC7.1
executable gives:
is a pointer to member function: 1
while the g++ executable gives
is a pointer to member function: 0

And on BCB5.5 it doesn't compile at all.

What's wrong with them? As 1 is my intentioned result, is that a bug of
g++?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Sharad Kala
Guest





PostPosted: Thu Dec 23, 2004 11:49 am    Post subject: Re: typetraits fail on pointer to member function? Reply with quote




"Ralph Zhang" <ralph623 (AT) 126 (DOT) com> wrote in message
Quote:
Hi,

I am reading Modern C++ Design and it mentions typetraits of pointer to
member function, so I write the following program to test that:

[snip]
--------------------------------------------------------------------------
-----
It compiles both on VC7.1 and g++ 3.3.3(cygwin), but the VC7.1
executable gives:
is a pointer to member function: 1
while the g++ executable gives
is a pointer to member function: 0

And on BCB5.5 it doesn't compile at all.

What's wrong with them? As 1 is my intentioned result, is that a bug of
g++?

Seems like a gcc bug to me. IMO VC++ is getting it correct i.e. it should
print 1. btw, Comeau online also agrees with VC++ (try to give array size as
TypeTraits<PtoMType>::isPtoM).

Sharad



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
L.Suresh
Guest





PostPosted: Thu Dec 23, 2004 5:09 pm    Post subject: Re: typetraits fail on pointer to member function? Reply with quote



This template specialization expectes a pointer to a member, not a
member function.

template <class U, class V> struct PtoMTraits<U V::*>
{
enum {result = true};
};

This will work...

struct Empty
{
int mem;
};

int main() {
typedef int (Empty::*PtoMType);
.....
}


--lsu


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.