1

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.

edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267
  • https://stackoverflow.com/q/16556681/1896169 – Justin Jul 08 '17 at 18:57
  • 1
    `foo{ boost::in_place( foo_t() ) }` definitely should be `foo{ boost::in_place( foo_t() ) }`; don't explicitly spell out template parameters to functions. – Justin Jul 08 '17 at 18:58

0 Answers0