Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2008-06-26 12:06:04


Frank Mori Hess wrote:
> On Thursday 26 June 2008 10:51 am, David Abrahams wrote:
>>> Don't you think it /always/ makes sense to provide a custom
>>> swap overload for a Swappable type, as long as it outperforms the
>>> default std::swap, in one way or the other?
>> That's the whole question. I'm not 100% sure.
>
> I'd say if the default std::swap compiles for the type, then there is no
> reason not to provide a more efficient swap specialization. The only
> question for me would be in a case where the type is not assignable/copy
> constructible. Then you might want to have a compile error instead of a non
> O(1) swap. But given that the default std::swap can in reality already have
> arbitrary complexity, depending on the complexity of a type's assignment/copy
> constructor, I don't see much value in producing a compile error.

That's an argument by implementation, not design. Who's to say that the
default std::swap wasn't just there to conveniently provide swap for PODs?

Well, I guess *I* can say that: the original sort implementations used
swap(), and the sort implementations only required CopyConstructible and
Assignable. Okay, I'm satisfied :-)

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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