Boost logo

Boost :

From: Eric Friedman (ebf_at_[hidden])
Date: 2003-09-11 02:03:21


Fernando,

Fernando Cacciola wrote:
> Inplace construction is now supported.

Great! I'm glad to see you got around to implementing this. I'd like to
offer it for variant as well.

[snip]
> you can initialize an optional constructing its contained
> value directly in place instead of copying an existing object:
>
> struct A
> {
> A ( int a, std::string s ) ;
> } ;
>
> boost::optional<A> opt( boost::in_place(1234,"Hellow world!") ) ;
>
> As you can see, the "factory expression" : in_place(...) does not
> need the optional's value_type (A in this case), so the
> syntax is terse.

Unfortunately this syntax will not work for variant. For example:

  struct B
  {
    B(int a, std::string s);
  };

  boost::variant<A,B> var(
      boost::in_place(1234,"Hello world!") // A or B?
    );

I'm guessing we could both have our desired syntax if there were also
boost::in_place overloads taking an explicit template argument.

Does this seem feasible to you?

Thanks,
Eric

P.S. Really though, I'm not sure if the following would be so terrible:

  boost::optional<A> opt(
      boost::in_place<A>(1234,"Hello world!")
    );

After all, it's not so different from:

  boost::optional<A> opt(
      A(1234,"Hello world!")
    );


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk