Template Specialization for T -> std::vector

后端 未结 4 820
情歌与酒
情歌与酒 2021-01-12 15:54

I have a template class method

template
T pop();

Now I want to do a template specialization as follows,



        
4条回答
  •  隐瞒了意图╮
    2021-01-12 15:59

    Off the top of my head, I usually get around it by using a one-member struct:

    template 
    struct pop_impl {
        static T pop(classname& x); // normal function
    };
    
    template 
    struct pop_impl> {
        static std::vector pop(classname& x); // specialized for std::vector
    };
    
    template 
    T classname::pop() { return pop_impl::pop(*this); }
    

提交回复
热议问题