Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-10-23 11:54:53


Pavol Droba <droba_at_[hidden]> writes:

> On Thu, Oct 23, 2003 at 09:42:35AM -0400, David Abrahams wrote:
>> Daniel Frey <daniel.frey_at_[hidden]> writes:
>>
>> > From a convenience POV, I would still prefer the copy-version to not
>> > have a suffix, but that's probably just a matter of taste. My main
>> > concern was safe use which is now addressed. Thanks.
>>
>> My taste agrees. The safer version should also be the more convenient
>> one.
>>
> If the inplace variant returns void, it could not be misused. So it
> is safe too.

Mutating in-place, regardless of the return type, is less safe than
making a new copy of the data. It's one of the basic principles of
functional programming, and why my coding guidelines recommend making
as many things const as possible, including function arguments.

   int f(int x)
   {
      if (condition) { ...
         modify(x);
      }
      ...

      int y = x + 3; // whoops, I forgot that x was modified
   }
           

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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