Getting a template class specialization based on a Base policy work for all derived policies

橙三吉。 提交于 2019-12-05 20:41:29

This is a case for SFINAE.

template< typename Policy, ...some_condition... >
struct Foo<Policy>
{
 ...
};

You should decide what is some_condition exactly. You can specify that Policy derives from BasePolicy:

template< typename Policy, enable_if< is_base<BasePolicy, Policy> > >

Or you can list allowed policies explicitly:

template< typename Policy,
           enable_if_c <is_same<Policy, BasePolicy>::value || 
                         is_same<Policy, DerivedPolicy1>::value> || 
                         ...whatever...
                        >
         >
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!