Class type at compile time

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

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

Kai-Uwe Bux

Christopher said:
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...

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
 
C

Christopher Benson-Manica

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

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

Jonathan Turkanis

Christopher Benson-Manica said:
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...

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

Jonathan
 
C

Christopher Benson-Manica

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

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?
 
J

Jonathan Turkanis

Christopher Benson-Manica said:
Derived> ?

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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top