default constructor - init boost::optional of non-copyable object -
what should initialize boost::optional< t >
if underlying type t
non-default constructible, non-copyable/moveable, one's instance still can exist?
is forbidden boost::optional
semantic reasons have member function template< typename... args > boost::optional< t >::construct(args && ...args)
, delivers arguments in-place operator new
construct object entirely (for non-ref type t
)? variant have non-member function std::make_shared< t >
.
it seems me, problem can solved means of using of std::unique_ptr
/std::shared_ptr
, in case question is: "why boost::optional
progress frozen?".
boost::optional
can initialized non-copyable type using in-place factories.
specifically, can use them this:
#include <boost/optional.hpp> #include <boost/utility/in_place_factory.hpp> class mytype : private boost::noncopyable { public: mytype(t1 const& arg1, t2 const& arg2); } ... boost::optional<mytype> m_var; ... m_var = boost::in_place(arg1, arg2); ...
in c++14 there proposed std::make_optional
better solution problem. however, has not been implemented in boost.optional.
Comments
Post a Comment