Jump to content
  • Advertisement
Sign in to follow this  
Nitage

template specialization

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way to specialize a template class based on whether one of the class template parameters inherits from a paticular class, or whether a template class parameter is an abstract class?

Share this post


Link to post
Share on other sites
Advertisement
Yes, but you will have to rely on SFINAE. If you have boost, what you are describing is a piece of cake.


#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/type_traits/is_abstract.hpp>

class some_base_class {};

template< typename Type
, typename Enabler = void
>
class your_class;

template< typename Type >
class your_class
<
Type
, typename ::boost::enable_if
<
::boost::is_base_and_derived
<
some_base_class
, Type
>
>
::type
>
{
};


template< typename Type >
class your_class
<
Type
, typename ::boost::enable_if
<
::boost::is_abstract
<
Type
>
>
::type
>
{
};



Of course, this requries that your class has an extra template parameter.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!