Boost logo

Boost :

From: John Maddock (John_Maddock_at_[hidden])
Date: 2000-01-16 07:39:16


>Probably (I wasn't there when iter_swap was introduced). But if
>iter_swap is implemented like:
>template <class ForwardIterator1, class ForwardIterator2>
>iter_swap(ForwardIterator1 a, ForwardIterator2 b)
> typedef typename iterator_traits<ForwardIterator1>::value_type
> value_type tmp(*a);
> *a = *b;
> *b = tmp;
>the performance is poor for heavy value_types that have otherwise
>specialized swap. But it does (usually) work with proxied references.

You missed a chance to push type_traits here :-)

By using "is_reference<typename
iterator_traits<ForwardIterator1>::reference>::value", iter_swap can
seemlessly switch between the "slow and safe" proxy iterator approach, and
calling swap (which is more likely to be specialised IMO), see the type
traits examples.

- John

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