Boost logo

Boost :

From: Philippe Mori (philippe_mori_at_[hidden])
Date: 2005-04-13 08:25:58

> Hi boosters,
> We often need to swap contents of two objects, but even more often we need
> to swap contents with no-throw exception guarantee.
> But currently we have no general way to swap two objects with no-throw
> exception guarantee. What we do have now is std::swap, and member
> functions which can be named swap, Swap, and so on. But now we can't
> swap arbitary types with no-throw exception guarantee in a general way.
> Yes, we can overload std::swap to support other than std:: types, but we
> can't guarantee that invocation of std::swap won't throw.

My opinion is that we should only have one swap function per object
type named swap. And we should always make it such that it won't

I think that the best thing would be that std::swap would only compile
for a given type T if the resulting function cannot throws (because
copy constructor and assigment would not throws) and thus having a
type trait would not be as much usefull.

OTOH, if we add type trait to indicate if swap is possible or if it will
then the defaut implementation should be able to deduce it from the traits
of the copy constructor and assignment operator. In particular swap of
POD types does not throws.

Also the compiler should be able to detect throw () specification and
provide the type trait itself.


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