Boost logo

Boost Users :

Subject: Re: [Boost-users] Usage of Boost.Optional
From: Marsh Ray (marsh_at_[hidden])
Date: 2010-11-27 23:34:56


On 11/27/2010 06:57 PM, Dean Michael Berris wrote:
>
> I'm not sure you understood the resolution of the discussion -- you
> will need to use the Boost.In_place_factory utility if you want to
> construct the resource in-place.

Haha, probably not. I admit to skimming it quickly mostly to confirm my
preconceptions. Looks like there were a couple more emails in the thread.

> On Sun, Nov 28, 2010 at 8:47 AM, Marsh Ray<marsh_at_[hidden]> wrote:
>>
>> Boost::optional is exactly what I want, it's just that it unnecessarily
>> requires a copy for deferred initialization.
>
> It's not required. You can use the in place factory for that.
>
> optional<foo> o;
> o = in_place<foo>(parameters, to, foo);

Cool, it works! (Rather it compiles, so I'll assume it works for now.)

Still, the documentation says it shouldn't:

http://www.boost.org/doc/libs/1_45_0/libs/optional/doc/html/boost_optional/detailed_semantics.html

> optional& optional<T (not a ref)>::operator= ( T const& rhs ) ;

> Notes: If *this was initialized, T's assignment operator is used, otherwise, its copy-constructor is used.

No mention of using in_place with operator=.

Thanks,

- Marsh


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net