By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,188 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,188 IT Pros & Developers. It's quick & easy.

Class type at compile time

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in
message news:cg**********@chessie.cirr.com...
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
Jul 22 '05 #2

P: n/a
Christopher Benson-Manica wrote:
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
Jul 22 '05 #3

P: n/a
Jonathan Turkanis <te******@kangaroologic.com> spoke thus:
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.

--
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.
Jul 22 '05 #4

P: n/a
Jonathan Turkanis <te******@kangaroologic.com> spoke thus:
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?

--
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.
Jul 22 '05 #5

P: n/a

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in
message news:cg**********@chessie.cirr.com...
Jonathan Turkanis <te******@kangaroologic.com> spoke thus:
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?


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
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.