开发者

total class specialization for a template

lets say i have a templated class

template <typename T>
struct Widget
{
   //generalized implementation
}

but i wanted to totally specialize.. for a template that accepted a parameter?

template <>
struct Widget< TemplateThatAcceptsParameter<N> >开发者_如何学运维
{
       //implementation for Widget for TemplateThatAcceptsParameterN 
       //which takes parameter N
}

How does one go about doing this?


This is called a partial specialization and can be coded like this:

template <typename T>
struct Widget
{
   //generalized implementation
};

template <typename N>
struct Widget< TemplateThatAcceptsParameter<N> >
{
   //implementation for Widget for TemplateThatAcceptsParameterN 
   //which takes parameter N
};

It works just like a regular specialization, but has an extra template argument.


template < typename N >
struct Widget< template_thing<N> >
{
  ...
};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜