Boost logo

Boost :

From: Martin Wille (mw8329_at_[hidden])
Date: 2005-04-13 09:57:32


Philippe Mori wrote:

> 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.

This implies that swap() would only be possible to implement in a
non-throwing fashion if 1. the cctor and the copy assignment operator
are accessible and 2. cctor and copy assignment operator do not throw.

This requirement is way too strong. E.g. the cctor of boost::array can
throw, because it allocates memory. However, the swap() function can
guarantee non-throwing operation when swap() for the value_type operates
non-throwing, too.

Even accessibility of a copy-ctor or a copy-assignment operator aren't
required. Classes like {i/o}stream aren't copyable. However, you could
imagine to swap objects of types which implement similar concepts.

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

Are throw specifications used for anything other then the dtors of
classes derived from std::exception? Many libraries don't use them
and they have reasons to avoid them.

Regards,
m


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