Re: [boost] Improving the assignment operators of various Boosttypes

David Abrahams wrote:
on Thu Sep 11 2008, Gevorg Voskanyan wrote:
[snip]
AFAIU, a swapping assignment operator taking the parameter by const ref adheres to the strong exception safety guarantee, whereas the one taking the parameter by value fulfills the nothrow guarantee. Not sure how practical and/or relevant the difference in this context is, though.
Is my observation above correct?
Well, technically, yeah... although the expression that does the assignment can still throw, so I don't think it makes much difference to say that it's nothrow. In other words, if I give you
f(std::string); // nothrow g(std::string&); // strong guarantee
For all practical purposes, you know that f and g have equivalent exception behavior because std::string's copy ctor can throw.
True, that's why I questioned the practicality of this difference :) Except perhaps for documenting a function's exception safety. Should it be considered while making aforementioned assignment operators in boost to take the argument by value?
I think this calculus might get more interesting when rvalue references are involved, because you can actually write stronger conditional guarantees.
My early impression is that rvalue references are going to make life much more interesting :-) Thanks for your time, Dave! Best Regards, Gevorg

on Thu Sep 11 2008, Gevorg Voskanyan <v_gevorg-AT-yahoo.com> wrote:
David Abrahams wrote:
on Thu Sep 11 2008, Gevorg Voskanyan wrote:
[snip]
AFAIU, a swapping assignment operator taking the parameter by const ref adheres to the strong exception safety guarantee, whereas the one taking the parameter by value fulfills the nothrow guarantee. Not sure how practical and/or relevant the difference in this context is, though.
Is my observation above correct?
Well, technically, yeah... although the expression that does the assignment can still throw, so I don't think it makes much difference to say that it's nothrow. In other words, if I give you
f(std::string); // nothrow g(std::string&); // strong guarantee
For all practical purposes, you know that f and g have equivalent exception behavior because std::string's copy ctor can throw.
True, that's why I questioned the practicality of this difference :) Except perhaps for documenting a function's exception safety. Should it be considered while making aforementioned assignment operators in boost to take the argument by value?
If you're asking whether such functions should be documented as nothrow after the modification, I think they should: it could be useful information for move-only types (with nonthrowing move ctors). -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (2)
-
David Abrahams
-
Gevorg Voskanyan