473,396 Members | 2,036 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Determining if type T is a subclass of X

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
5 1740
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Murat Tasan | last post by:
so i have a situation that i know cannot be solved directly, and i've already worked around it, but i was hoping to find an explanation as to why this behavior is as it is... i have an abstract...
21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
0
by: Stephen Nesbitt | last post by:
All: Here's my implementation problem. I have a base class which has the responsibility for providing entry into the logging system. Part of the class responsibility is to ensure that lagger...
3
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I subclass datetime and timedelta >>> dt = myDatetime(1970,1,1) >>> type(dt) <class 'dtime.myDatetime'>
8
by: Mark English | last post by:
I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each "attribute" of that class. The user could enter values for the attributes and on closing the window...
1
by: Brian van den Broek | last post by:
Hi all, The code below exhibits an attempt to refer to the type of a __Class from within a method of that class. I've been unable to figure out how to make it work as I want, and would...
3
by: john | last post by:
I have a situation where i have a base class and a sub-class. A null instance of the sub-class is passed into a function. The function needs to create a new instance of the sub-class, but the...
23
by: René Nordby | last post by:
Hi there, Is there anyone that knows how to do the following? I have a class A and a class B, that 100% inherits from class A (this means that I don't have other code in class B, than...
5
by: JH | last post by:
Hi I found that a type/class are both a subclass and a instance of base type "object". It conflicts to my understanding that: 1.) a type/class object is created from class statement 2.) a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.