Boost logo

Boost :

Subject: Re: [boost] [utility] new auto_buffer class --- RFC
From: Scott McMurray ([hidden])
Date: 2009-03-14 22:17:19

On Sat, Mar 14, 2009 at 04:47, Thorsten Ottosen
<thorsten.ottosen_at_[hidden]> wrote:
> David Abrahams skrev:
>> A class that attempts to provide value semantics but doesn't support x = x
>> is putting a big hole in the system of equational reasoning.  Justifying
>> that (to me) would take some pretty heavy proof.
> I have not really seen code that exhibits x = x. I've seen lot's of
> discussion (e.g. Sutter & Meyers). Does anybody write such code?

On purpose? Doubtful. Does it happen? Probably.

Is there really a cost to allowing it, though? I'd assume it would
have a vector-like operator= that'd be something like this:

copy(other.begin(), other.begin() + size(), begin());
if (size() > other.size()) erase(begin()+other.size(), end());
else insert(end(), other.begin()+size(), other.end());

That works fine when this == &other, and I can't see a reason it would
be slower than some version that doesn't allow self-assignment. Sure,
it means self-assignment is O(n), but that's acceptable and
consistent. It's sufficiently exception-safe, too.

Boost list run by bdawes at, gregod at, cpdaniel at, john at