Boost logo

Boost :

Subject: Re: [boost] [utility] new auto_buffer class --- RFC
From: John Bytheway (jbytheway+boost_at_[hidden])
Date: 2009-03-02 14:52:44

Thorsten Ottosen wrote:
> Frank Mori Hess skrev:
>> Hash: SHA1
>> On Monday 02 March 2009, Thorsten Ottosen wrote:
>>> where v.resize() should never actually shrink the buffer.
>>> (Do we need another function that does that?), or should we simply
>>> rename v.resize(n) to v.ensure_capacity(n).
>> I believe the usual way std::vector handles this is that resize()
>> never reduces capacity, and if you do want to reduce capacity you have
>> to swap your vector with a newly constructed one. Hmm, your
>> auto_buffer doesn't support swap though.
> No. As it might be O(n). I'm not against providing "swap()", it should
> just be under a different name, e.g. liniear_swap().

Certainly swap should be provided somehow; a fast-as-possible swap is
not otherwise possible since the user can't get at the buffer pointer.

boost::array supports swap, and yours should be at least as fast as
that. On that precedent I'd say you should support swap() under that
name. Has anyone ever complained about the deceptive slowness of
boost::array's swap?

Also, I think the following sort of code is quite plausible:

std::pair<int, auto_buffer<int, 2> > a,b;

(e.g. I often find myself sorting vectors of such pairs) and for that to
work you need to provide a free swap overload.

John Bytheway

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