Specialize a template with a template

后端 未结 2 705
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 06:31

I have a (free) function template that looks like this

template 
T get();

I now want to specialize this function for a class,

2条回答
  •  情书的邮戳
    2021-01-21 07:16

    As Nawaz said, the standard just doesn't allow you to do that. You could however extract the implementation into the static method of a class and partially specialize that class.

    template
    struct get_impl{
      static T get(){ ... }
    };
    
    template
    struct get_impl >{
      static foo_type get(){ ... }
    };
    
    template
    T get(){ return get_impl::get(); }
    

提交回复
热议问题