I've been trying to define a defaulted move constructor in a class with a boost::optional
member variable.
#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));
}
My compiler supports both move semantics and defaulted move constructors, but I cannot get this to work.
% 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.
Is there a way to move a boost::optional
without modifying Boost's source code? Or should I wait until Boost supports moving?
I had the same problem with boost::any
in the past.
Boost.Optional supports move construction only since Boost version 1.56. See the release notes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With