Boost logo

Boost Users :

Subject: Re: [Boost-users] Usage of Boost.Optional
From: John Dlugosz (JDlugosz_at_[hidden])
Date: 2010-10-28 12:27:33


> > Just assign your D instance to 'd' when you want to do so.
> >
>
> I think what the OP was looking for is a move constructor for
> Boost.Optional which I don't think it supports (yet).
>
> --

I don't want to create a different D instance and then assign it to d, since D cannot be copied. If I were using a compiler that supported move references, I could add a move assignment to class D, but I'm not. I want to say "construct d with these constructor arguments, now."

        new optional<D> ((void*)&d) (in_place(args));

might do the trick in the special case where it was indeed uninitialized before (it doesn't call the destructor of the old value), but that's a dirty trick. I show it to better indicate what I'm after: initialize (not assign) from arguments, within the body of an if statement, not at the normal initializer.

I think d.reset(in_place(args)) would do the trick, so I propose that as a logical missing consequence of existing features.

--John

---corporate footer---

TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.


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