Click here to Skip to main content
13,249,813 members (83,909 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


Posted 7 Feb 2012

Quickly Check whether C++ Template Instances have the Same Parameters

, 9 Feb 2012
Rate this:
Please Sign up or sign in to vote.
This post helps to quickly check whether C++ template instances have the same parameters.

Setting up a custom type identification mechanism only makes sense if RTTI is not available or you cannot guarantee that it is consistent. That might be the case on some platforms with dynamic libraries.

A simple static_cast will not work for all possible inheritance paths. Also, your method generates a different id in each translation unit ChildClass<t> is pulled into. I have yet to see a solution for "safe" class IDs mechanism fundamentally different from that used by COM.

So if you have RTTI, you just do this:

virtual bool equals(BaseClass *other) const
    if (auto temp = dynamic_cast<ChildClass<T>*>(other)) {


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

paul michalik
Software Developer
Germany Germany
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralIs this faster than my method? It is surely safer, but my go... Pin
Sebastian Krysmanski7-Feb-12 22:13
memberSebastian Krysmanski7-Feb-12 22:13 
GeneralRe: Faster? Probably not, a dynamic_cast can have considerable c... Pin
paul_719-Feb-12 21:34
memberpaul_719-Feb-12 21:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171114.1 | Last Updated 10 Feb 2012
Article Copyright 2012 by paul michalik
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid