In this question I have an answer to initialize an optional
with run( std::in_place, ctor_arg )
to get in-place initialization. Alas, some of my target platforms appear not to support this yet. Is there a pre-C++17 equivalent using boost::optional
?
That is, I have an optional<foo> foo
and wish to initialize it in place in the constructor initialization list:
class outer {
boost::optional<foo_t> foo;
outer() :
foo{ boost::in_place } // ???
I've attempted foo{ boost::in_place<foo_t>( foo_t() ) }
based on what I found in the boost docs, but I'm uncertain it's correct. I'm getting a segfault on my constructor relating to the value here and would like to exclude my possibly incorrect optional construction as the cause.