This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Why doesn't iter_swap use swap?
On Mon, Aug 23, 2004 at 03:36:27PM -0600, Martin Sebor wrote:
> chris wrote:
>
> >One reason discussed in the standard about why not to use swap() is that
> >iter_swap may work in some places where swap() doesn't (vector<bool> is
> >mentioned). I'm not an expert on this, but we seem to in general require
> >"normal assignment" in for example __unguarded_linear_insert, and other
> >places.
>
> The "new" iter_swap will also not work in cases where the two
> iterators' value_types are distinct types:
>
> int i;
> double d;
> std::iter_swap (&i, &d);
chris and I discussed this on #c++ briefly. Code like this generates
warnings already. Our iter_swap implementation does convertibility testing
when concept checks are on, but only a simple assignment of the values.
There's no attempt at, e.g., typecasting. (Nor do I think there should be.)
So I feel this shouldn't hold back anything.
Is there real-world code which exploits this capability? We also talked
about that, and nobody could think of any offhand.
I like the idea of requiring that the types be the same, in order to permit
iter_swap to use swap. We'd also need to add appropriate specializations
and overloads to handle things like list iterators properly.
--
Behind everything some further thing is found, forever; thus the tree behind
the bird, stone beneath soil, the sun behind Urth. Behind our efforts, let
there be found our efforts.
- Ascian saying, as related by Loyal to the Group of Seventeen