Connecting Tech Pros Worldwide Help | Site Map

Class type at compile time

Christopher Benson-Manica
Guest
 
Posts: n/a
#1: Jul 22 '05
I know there's a way to determine whether a given class is a
member of a given class hierarchy at compile time, but I'll be darned
if I can find it again. Can someone help? Thanks...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jonathan Turkanis
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Class type at compile time



"Christopher Benson-Manica" <ataru@nospam.cyberspace.org> wrote in
message news:cg0alv$grr$1@chessie.cirr.com...[color=blue]
> I know there's a way to determine whether a given class is a
> member of a given class hierarchy at compile time, but I'll be[/color]
darned[color=blue]
> if I can find it again. Can someone help? Thanks...[/color]

Perhaps you're looking for boost::is_base_and_derived<Base, Derived> ?

Jonathan


Kai-Uwe Bux
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Class type at compile time


Christopher Benson-Manica wrote:
[color=blue]
> I know there's a way to determine whether a given class is a
> member of a given class hierarchy at compile time, but I'll be darned
> if I can find it again. Can someone help? Thanks...
>[/color]

Recommendation: use Boost.

#include <boost/type_traits.hpp>

boost::is_base_and_derived<T,U>::value

is true if U derives from T and false otherwise.)



Best

Kai-Uwe Bux
Christopher Benson-Manica
Guest
 
Posts: n/a
#4: Jul 22 '05

re: Class type at compile time


Jonathan Turkanis <technews@kangaroologic.com> spoke thus:
[color=blue]
> Perhaps you're looking for boost::is_base_and_derived<Base, Derived> ?[/color]

Yes, that was it. Unfortunately, I can't use boost, but at some point
I implemented it myself. Too bad I can't find that code anymore ;(
Anyway, thanks.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Christopher Benson-Manica
Guest
 
Posts: n/a
#5: Jul 22 '05

re: Class type at compile time


Jonathan Turkanis <technews@kangaroologic.com> spoke thus:
[color=blue]
> Perhaps you're looking for boost::is_base_and_derived<Base, Derived> ?[/color]

I also was positive that I originally saw this in Stroustrup's Style
and Technique FAQ, but it doesn't seem to be there now. Am I just
crazy, or is there an underlying reason why I might have had such a
delusion?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jonathan Turkanis
Guest
 
Posts: n/a
#6: Jul 22 '05

re: Class type at compile time



"Christopher Benson-Manica" <ataru@nospam.cyberspace.org> wrote in
message news:cg0cd9$h12$1@chessie.cirr.com...[color=blue]
> Jonathan Turkanis <technews@kangaroologic.com> spoke thus:
>[color=green]
> > Perhaps you're looking for boost::is_base_and_derived<Base,[/color][/color]
Derived> ?[color=blue]
>
> I also was positive that I originally saw this in Stroustrup's Style
> and Technique FAQ, but it doesn't seem to be there now. Am I just
> crazy, or is there an underlying reason why I might have had such a
> delusion?[/color]

Isn't being crazy a good reason for a delusion? ;-)

I don't have time to check Stroustrup's site now, but my recollection
was that most of his techniques were related to producing compiler
errors if a type doesn't conform to a concept.

Anyway, you should be able to use a modified version of the boost
implementation, which is fairly self-contained. If you don't have to
worry about ambiguous and private bases you should be able to simplify
it considerably.

Jonathan


Closed Thread