相关疑难解决方法(0)

是否可以移动boost :: optional?

我一直试图在一个带有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));
}
Run Code Online (Sandbox Code Playgroud)

我的编译器支持移动语义和默认的移动构造函数,但我不能让它工作.

% 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.
Run Code Online (Sandbox Code Playgroud)

有没有办法移动a boost::optional 而不修改Boost的源代码?或者我应该等到Boost支持移动?

我过去遇到了同样的问题boost::any.

c++ boost move-semantics c++11 boost-optional

25
推荐指数
2
解决办法
6500
查看次数

标签 统计

boost ×1

boost-optional ×1

c++ ×1

c++11 ×1

move-semantics ×1