Re: [boost] [optional] Thoughts on disallowing assignment for wrapped references.

Fernando Cacciola wrote:
optional<T> f() { optional<T> result; // do stuff return result; }
However, in the latter case, there is no loss of generality since the above would still be a no-no where T a reference type... Or did I miss something in your response?
You totally missed his point.
Indeed.
In Robert's example, it is easy to see--or should be easy to see--that the fact that the optional<T> is being returned is secondary, perhaps even irrelevant, to the point he is making His point is about the shortcoming of lacking assignment, not about object lifetimes (and BTW, is the same point Nevin and I made earlier).
I wouldn't go quite that far...
Perhaps a less distracting example would be:
optional<T> o ;
switch ( cond ) { case a : o = foo1(); break ; case b : o = foo2(); break ; case c : o = foo3(); break ; case e : o = foo4(); break ; case e : o = foo5(); break ;
default : // o remains uninitialized }
Notice that is quite possible to encounter the above example in real-life, as it is common that a variable remains uninitialized in the default case of a switch (or, for that matter, in any branch of a complex conditional).
In fact, I even wonder if that example couldn't be considered as the canonical use case for optional<>'s assignment operation.
The one thing you overlook in your example is that there are reasonable alternatives to using optional within a local scope. However, when returning a value from a function, ownership must be transferred to the caller, which reduces the safe options. Regardless, disallowing assignment for reference types which, in effect, "reseats a reference," is surprising in too many cases. A new, non-assignable optional type might gain traction, but removing assignment from optional<T&> is not acceptable. _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com ________________________________ IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On Wed, 07 Sep 2011 04:01:31 -0700, Stewart, Robert <Robert.Stewart@sig.com> wrote:
Regardless, disallowing assignment for reference types which, in effect, "reseats a reference," is surprising in too many cases. A new, non-assignable optional type might gain traction, but removing assignment from optional<T&> is not acceptable.
To reiterate, I am not advocating such a removal. As for a new, non-assignable optional type, I'm not yet in a position to broach a suggestion. I am still educating myself on the alternative approaches that have been discussed. Part of this education process has been the discussion in this thread, part has been trawling the archives. Unfortunately, the latter case is not only laborious, but also it's quite easy to miss relevant discussions that may not have shown up in search results. I've come to the conclusion that for such a contentious and much discussed issue, a matrix of current and alternative behaviours with a pros/cons section is needed, with any clarifying text added as a reference. In the next few days I hope to work on such a matrix. Once completed, the pros/cons can then be evaluated for completeness, and afterwards any other alternative behaviour that may not have been explored/discussed can be added to the matrix as needed. In the least, this will certainly help people who are new to optional, and are uncomfortable with its current behaviour, and may want to modify it in which ever way they see fit understand the relevant alternatives and their pros/cons. To boot, it may help with a design rationale for the documentation of optional. Once the matrix is complete, let's see if there are any appealing alternatives. Mostafa

On Wed, 07 Sep 2011 04:01:31 -0700, Stewart, Robert <Robert.Stewart@sig.com> wrote: <snip> Hi Robert, In my usual newsreader I noticed that this last message (see date and time stamp above) of yours and my subsequent response was not threaded appropriately, ie, not threaded to the original thread. (The header of your last message had no references.) Should I rethread these? Mostafa

Mostafa wrote:
In my usual newsreader I noticed that this last message (see date and time stamp above) of yours and my subsequent response was not threaded appropriately, ie, not threaded to the original thread. (The header of your last message had no references.) Should I rethread these?
I use my mail client at work to manage the list. I've never heard that it mishandled headers before, so I'm surprised there was a problem. Having no idea how to rethread messages, or how much work that implies, combined with not knowing the extent of the problem you've observed, I can't say whether you should rethread the messages. _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com ________________________________ IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
participants (2)
-
Mostafa
-
Stewart, Robert