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 

has_member_name for VC6?

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





PostPosted: Thu Jun 26, 2003 10:33 pm    Post subject: has_member_name for VC6? Reply with quote



Hello!

OK, lets write the whole stuff again, sigh!

Some days ago, Markus Werle posted as a reply to the thread
"How to use function objects to select output operator" a very usefull
class template named has_member_name, which provides a compiletime
check, whether a given type provides a name "name", referring it to
Paul Mensonides.
For those, who don't find this posting, I repeat its canonical
implementation
here (Some compilers, like gcc 3.4 need a small work-around as Markus
showed us):

template<class T>
class has_member_name
{
protected:
template<class U> static char check(typename U::name*);
template<class U> static char (& check(...))[2];

public:
enum { value = (sizeof(check<T>(0)) == 1) };
};

Belief it or not, but neither this implementation nor the proposed
workaround
(not quoted here) don't compile with VC6....
After you have stopped banging your head at your keyboard, or, depending
on
your mood, stopped laughing resoundingly, I honestly want to ask you
whether
anyone can show me an implementation, which works for VC6!!

I tried it several after hours and got one "internal compiler error"
after the other,
but in the end wasn't successful - aaaarg!

One further comment: One disadvantage of this template is, that a test
for another
"name", e.g. value_type needs another class template. Currently I only
see a
solution by introduction of two macros, like

#define DEFINE_HAS_NAME(aName)
template<class T>
class has_member_##aName
{
protected:
template<class U> static char check(typename U:: aName*);
...
}

#define HAS_NAME(aType, aName) (has_member_##aName < aType >::value)

Or did anyone find a metaprogramming technique to achieve a similar
result?

Thanks for you ideas!

Daniel from Bremen




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





PostPosted: Fri Jun 27, 2003 6:00 pm    Post subject: Re: has_member_name for VC6? Reply with quote



Daniel Spangenberg wrote:

Quote:
Hello!

OK, lets write the whole stuff again, sigh!

No, no.
David Abrahams pointed me to a boost macro
for things like that, so please check
www.boost.org and especially the file
../boost/mpl/aux_/has_xxx.hpp


BTW: Intel C++ is free on Linux platforms at present.
Also g++ is beginning to get stable again.
Take the chance and get rid of any compiler problems
and commercial platform at once.

If this is not possible, how about using cygwin
or maybe you should give Comeau a try?


Markus

--

Build your own Expression Template Library with Daixtrose!
Visit http://daixtrose.sourceforge.net/

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

Back to top
David Abrahams
Guest





PostPosted: Mon Jul 07, 2003 8:46 pm    Post subject: Re: has_member_name for VC6? Reply with quote



Daniel Spangenberg <dsp (AT) bdal (DOT) de> writes:

Quote:
Guten Morgen, Markus!

Markus Werle schrieb:

Daniel Spangenberg wrote:

Hello!

OK, lets write the whole stuff again, sigh!

No, no.

My sigh was the mourning about my first posting which was lost, as the
mods sayed...

David Abrahams pointed me to a boost macro
for things like that, so please check
www.boost.org and especially the file
./boost/mpl/aux_/has_xxx.hpp

BTW: Intel C++ is free on Linux platforms at present.
Also g++ is beginning to get stable again.
Take the chance and get rid of any compiler problems
and commercial platform at once.

If this is not possible, how about using cygwin
or maybe you should give Comeau a try?

Thank you for the pointer to boost/mpl/aux_/has_xxx.hpp.
I first had a (short) look at the traits type implementation,
but maybe too short.

I understand, that the original implementation works for
most other compilers, and in the moment we are moving
to VC7.1. But I have to ensure that the whole stuffs also
runs with VC6 Sad(

The Boost implementation does work with vc6 and vc7.0. Known
compilers with which it doesn't work are:

GCC < 3.0
Metrowerks < Pro8
Borland C++ 5.5.1 (not sure about newer Borlands).

--
Dave Abrahams
Boost Consulting
www.boost-consulting.com

[ 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.