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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -