Boost logo

Boost :

From: Philippe Mori (philippe_mori_at_[hidden])
Date: 2005-04-13 11:35:12

>> 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
>> throws.
> What if class only has Swap function? What to do then?
> Or swap can throw? (boost::array for example)

Well I did not know about boost::array that could throw so I was
assuming that "standard" swap were never throwing...

> Yeah, some assumptions can be made, but not only for POD types and some
> other trivial cases.
> So we need to explicitly register type.

Well, with some compiler supports, we can know in some situation
that it would not throw particulary if the compiler (or library) already
implement some type traits like has_no_throw_copy<T>...

But effectively, I guess that most of the time when swap is defined
specifically for a type, it won't throws and the compiler won't knows.

So the best thing that the compiler would probably be able to do
(if no specific traits exist for a given type T) is to detect if the
implementation is used and if so the type trait would be implemented
in term of has_no_throw_assign<T> and has_no_throw_copy<T>.

>> Also the compiler should be able to detect throw () specification and
>> provide the type trait itself.
> Too many people don't use throw specifications, but their swap still not
> throws.

If the specification is used and it is possible to know it (on that
implentation) then the default would be deduce from that instead
of always being false. User can always provide a specilization
if needed.

I think that for consistency, the trait should be has_nothrow_swap<T>
(see C++ Template Metaprogramming page 27).

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