|
Boost : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2000-01-13 09:24:21
Darin Adler wrote on 1/13/2000 2:52 AM
>> with a statement like:
>>
>> swap(*i, *j);
>
>Wasn't this the motivation for iter_swap? But for some reason it was
>insufficient?
Probably (I wasn't there when iter_swap was introduced). But if
iter_swap is implemented like:
template <class ForwardIterator1, class ForwardIterator2>
void
iter_swap(ForwardIterator1 a, ForwardIterator2 b)
{
typedef typename iterator_traits<ForwardIterator1>::value_type
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.
A higher performance iter_swap is to just call swap. But that breaks
proxied references unless the proxy specializes swap.
One could retain the lower performance iter_swap, but recommend that
iterators of heavy value_types overload iter_swap. But it seems easier
to just overload swap in the proxy when required. Still, you could
overload the higher performance iter_swap as another way to get around a
broken proxy.
-Howard
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk