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

Determining if type T is a subclass of X

P: n/a
Hi,

Is there a way using templates at compile time to determine if a type
T is a subclass of another type?

Basically I want to chose one struct if it is a subclass, or another
struct if it is not.

Jun 4 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
flopbucket wrote:
Is there a way using templates at compile time to determine if a type
T is a subclass of another type?

Basically I want to chose one struct if it is a subclass, or another
struct if it is not.
Yes, IIRC. Check "is_derived_from" (or something like that) in Boost.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 4 '07 #2

P: n/a
flopbucket wrote :
Hi,

Is there a way using templates at compile time to determine if a type
T is a subclass of another type?

Basically I want to chose one struct if it is a subclass, or another
struct if it is not.
Yes there is, see boost::is_base_of

http://www.boost.org/doc/html/boost_...its.is_base_of

- Sylvester
Jun 4 '07 #3

P: n/a
On Jun 4, 10:27 am, Sylvester Hesp <s.hes...@SPAMoisyn.nlwrote:
flopbucket wrote :
Hi,
Is there a way using templates at compile time to determine if a type
T is a subclass of another type?
Basically I want to chose one struct if it is a subclass, or another
struct if it is not.

Yes there is, see boost::is_base_of

http://www.boost.org/doc/html/boost_...e.html#boost_t...

- Sylvester
Is it possible to do this without using Boost library functions ???

Jun 4 '07 #4

P: n/a
Vaibhav <va***********@gmail.comwrote in news:1180967826.331580.90410
@p77g2000hsh.googlegroups.com:
On Jun 4, 10:27 am, Sylvester Hesp <s.hes...@SPAMoisyn.nlwrote:
>flopbucket wrote :
Hi,
Is there a way using templates at compile time to determine if a type
T is a subclass of another type?
Basically I want to chose one struct if it is a subclass, or another
struct if it is not.

Yes there is, see boost::is_base_of

http://www.boost.org/doc/html/boost_...e.html#boost_t...

- Sylvester

Is it possible to do this without using Boost library functions ???

Sure. Look at how Boost did it... do the same thing.
Jun 4 '07 #5

P: n/a
On 4 juin, 16:14, flopbucket <flopbuc...@hotmail.comwrote:
Hi,

Is there a way using templates at compile time to determine if a type
T is a subclass of another type?

Basically I want to chose one struct if it is a subclass, or another
struct if it is not.
Look at "Modern C++ Design" - Alexandrescu
The whole process is explained (and used in Loki).

Jun 4 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.