Subject: Re: [boost] [utility] new auto_buffer class --- RFC
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2009-03-14 22:17:19
On Sat, Mar 14, 2009 at 04:47, Thorsten Ottosen
> 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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk