Boost logo

Boost :

Subject: Re: [boost] [tuple] swap (also includes question about [sorting])
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-05-17 01:13:04


Jeremiah Willcock wrote:
> Thanks to Marcin Zalewski, the problem in my last email has been
> tracked down to the inability to swap boost::tuples that contain
> references. There have been a couple of proposals to add that:
> but it appears that none of them has made it into Boost. This feature
> is important because of sorting data structures using zip_iterators as
> in my previous message:
> and the older posts:
> In particular, std::swap (from GCC 4.0.1) does not work correctly on
> the result of dereferencing a zip_iterator, which is a Boost tuple of
> references. The std::swap function does not work at all (fails at
> compile time) because the result of operator* is not a non-const
> reference, and std::iter_swap tries to use assignment between the
> tuples, producing incorrect answers at run time. Is it true that
> there is no standards-compliant way to solve this problem? If so,
> would that be a good justification for Boost.Sorting to include an
> algorithm similar to std::sort but that handles more generalized
> swappable types?

Even overloading swap is insufficient, since the standard does not
specify that
std::sort calls swap using ADL or even that it calls any swap at all.
In particular
overloading swap will not work on msvc, because std::sort calls
(without ADL), which in turn calls std::swap.

In Christ,
Steven Watanabe

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