I have a non-movable and non-copyable type:
struct A
{
A(std::string p1, int p2){}
A(A const &) = delete;
A(A&&) = delete;
A& operator=(A const &) = delete;
A& operator=(A&) = delete;
};
I can construct boost optional this way:
boost::optional<A> op(boost::in_place("abc", 5));
I also need to initialize boost::optional<A> which is a class member. Here is my solution:
class B
{
public:
B(const boost::optional<A>& op): op_(op) {}
private:
const boost::optional<A>& op_;
};
B b(boost::optional<A>(boost::in_place("abc", 5)));
Is it possible to have just boost::optional<A> class member and initialize it somehow ?
Edit (clarification)
I would like to have boost::optional<A> op_ class data member but I don't know how to initialize it.
You can declare the constructor of
Basand instantiate
BasNote that I change the data member
op_to not be reference here, as opposed to the definition ofBin your question.