C++: error “explicit specialization in non-namespace scope”

前端 未结 2 2192
情深已故
情深已故 2021-02-20 11:12
template
class Bimap {
public:
    class Data {
    private:
        template Data& set(T);
        template<>         


        
2条回答
  •  暖寄归人
    2021-02-20 11:36

    @Albert

    I had a similar problem when I wanted to add a "trim-excess-capacity" to a custom made container. The std::vector swap trick and changing the declaration of the existing container were not valid options. So I've come up with this:

    template  struct DeleteImp
    {
        static void Trim(T* to, unsigned int count);
    };
    
    template  struct DeleteImp       
    {
        static void Trim(T* to, unsigned int count) {}
    };
    
    template  struct DeleteImp        
    {
        static void Trim(T* to, unsigned int count)
        {
            for(unsigned int i=0; i

    used by my container like this:

    DeleteImp::isPointer>::Trim(buf + length, truelength-length);
    

    You may also want to check out this resource.

提交回复
热议问题