Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 756183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:12:57+00:00 2026-05-14T15:12:57+00:00

In my application, there is a inheritance hierarchy in which only the classes that

  • 0

In my application, there is a inheritance hierarchy in which only the classes that are at the end of the inheritance chain are non-abstract classes. Also there is some usage of boost::variant. I want to write a function which takes a pointer and a Type and says whether the object belongs to that type.

For example

#define IsA(nodeptr, type)   ( checkType<type>(nodeptr) ) 

template<typename Type, bool isAbstract, typename PtrType >
class CheckType
{
    bool operator()( PtrType* ptr ) { return ( typeid(*ptr) == typeid(Type) ); }
};

template<typename Type, typename PtrType >
class CheckType < Type, true, PtrType >
{
    bool operator()( PtrType* ptr ) { return ( dynamic_cast<Type*>(ptr) != NULL ); }
};

template<typename Type, BOOST_VARIANT_ENUM_PARAMS(typename T) >
class CheckType< Type, false, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
{
    bool operator()( boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>* ptr ) 
    { 
        return ( ptr->type() == typeid(Type) ); 
    }
}

template< typename Type, typename PtrType >
bool checkType( PtrType* nodePtr )
{
    CheckType<Type, boost::is_abstract<PtrType>::value, PtrType> check;
    return check(nodePtr);
}

Now if there is a boost variant, i want to find out whether the boost variant stores that particular type. Can someone help me with that? I don’t want to add an extra parameter to find out whether it is a variant. Even for finding out the abstractness, i am using boost::is_abstract..

Thanks,
Gokul.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:12:57+00:00Added an answer on May 14, 2026 at 3:12 pm

    Well there are two direct versions of this:

    return (boost::get<Type*>(v) != 0);
    

    And this:

    return ( v.type() == typeid(Type) );
    

    I am not sure how to handle that with your template overloading cleanly but you could do something like this:

    template< typename Type, bool TypeisAbstract, bool TypeIsVariant,
              typename ptrType >
    bool checkType( ptrType* t)
    {
        return ( typeid(*t) == typeid(Type) );
    }
    
    template< typename Type, typename ptrType >
    bool checkType<Type, true, false, ptrType>( ptrType* t)
    {
        return ( dynamic_cast<Type*>(t) != NULL );
    }
    
    template< typename Type>
    bool checkType<Type, false, true, ptrType>(const boost::variant& v)
    {
        return ( v.type() == typeid(Type) );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application, where there are many forms which follow visual form inheritance.
Some where in the application there is an autogenerated query like SELECT DISTINCT `Name`,`Number`
In my application there is language detection. Languages have some identification code like en
I have an application that implements something like a Chain of Responsibility in Python.
I saw that there's many, many thread about this on the web, also in
I'm creating an application that allows a user to create widgets. There are several
For my project management application, I am currently using Single Table Inheritance so that:
I have a hierarchy of classes mapped into hibernate that looks kind of like
I have an application that will only stop/start services if it is run as
In my application there are courses which have steps. (A user proceeds though the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.