我正在尝试创建一个不可复制类型的变体 可能使用递归包装器,如下面的代码:
#include "boost/variant.hpp"
using namespace std;
using namespace boost;
struct A
{
A() {}
A(A &&) noexcept {}
A& operator=(A &&) noexcept {}
A(A const &) = delete;
A& operator=(A const &) = delete;
};
struct B;
typedef variant<A, recursive_wrapper<B>> ABC;
struct B
{
B() {}
B(B &&) noexcept {}
B& operator=(B &&) noexcept {}
B(B const &) = delete;
B& operator=(B const &) = delete;
};
int main(int argc, char** argv)
{
ABC _a, _b;
_b = std::move(_a);
}
问题在于,如果我对移动赋值进行编码,则递归包装器期望对象可以进行复制构造。这是我得到的编译错误:
/usr/include/boost/variant/recursive_wrapper.hpp:116:32: error: use of deleted function 'B::B(const B&)'
: p_(new T( operand.get() ))
有人看到问题在哪里吗?