
John Bytheway skrev:
Thorsten Ottosen wrote:
Frank Mori Hess skrev: 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?
I don't know. I just stay clear of it. The point is that we don't want inexperienced users to use an O(n) swap accidently.
Also, I think the following sort of code is quite plausible:
std::pair<int, auto_buffer<int, 2> > a,b; //... swap(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.
Ok. That justifies some way of performing the swap. -Thorsten