重载的构造函数非法移动和复制

Cof*_*ode 3 c++ templates c++14 forwarding-reference

我有一个我正在编写的类,它将为其中一个构造函数采用特殊类型,它可以是符合我要求的任何类型.我遇到了这个模板化构造函数导致我的副本并将构造函数移动为非法重载的问题!

我的班级是这样的:

template<typename ... Types>
class myclass{
    public:
        myclass(const myclass &other){/* copy constructor */}
        myclass(myclass &&other){/* move constructor */}

        template<typename Special>
        myclass(Special &&arg){/* stops copy/move implementations */}
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个限制?

T.C*_*.C. 5

限制它.

template<typename Special,
         std::enable_if_t<!std::is_same<std::decay_t<Special>, myclass>{}, int> = 0 >
myclass(Special &&arg) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)

根据您的特定用例,您可能还希望Special进一步限制仅适合您要求的类型.