我一直在尝试在具有boost::optional
成员变量的类中定义默认的移动构造函数。
#include <boost/optional.hpp>
#include <utility>
#include <vector>
struct bar {std::vector<int> vec;};
struct foo {
foo() = default;
foo(foo&&) = default;
boost::optional<bar> hello;
};
int main() {
foo a;
foo b(std::move(a));
}
我的编译器同时支持移动语义和默认的移动构造函数,但我无法让它工作。
% clang++ foo.cc -std=c++11 -stdlib=libc++ foo.cc:15:7: error: call to deleted constructor of 'foo' foo b(std::move(a)); ^ ~~~~~~~~~~~~ foo.cc:9:3: note: function has been explicitly marked deleted here foo(foo&&) = default; ^ 1 error generated.
有没有办法在boost::optional
不修改 Boost 源代码的情况下移动 a?还是我应该等到 Boost 支持移动?
我过去也有同样的问题boost::any
。