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?
chris jefferson wrote:
Daniel Frey wrote:
I'm currently discussing the same problem (swap, iter_swap and DR 187)
with some Boost folks. While it looks promising at first that
iter_swap uses ADL to find specializations, it is also intrusive for
the user as he can no longer protect calls from ADL by qualifying
them. Also, if a qualified call to iter_swap uses ADL internally, why
doesn't a qualified call to swap uses ADL, too? Technically it's
possible, Howard Hinnard already tried it out in the Metrowerks STL.
We are still undecided whether or not this is a good idea.
However, at least in stdlibc++, almost all uses of iter_swap are written
std::iter_swap. Therefore at the moment there is no way to user-defined
overloads, as users can't (or really, really shouldn't) put things in
std::, and iter_swap doesn't call swap. I think this is a worse situation
Maybe I should separate issues more clearly. This first issue is, how
std::iter_swap should be implemented. The text of DR 187 suggests that
is makes an unqualified call to swap. I think this is intrusive to the
user as it activates ADL. I think this should be avoided as we don't
have evidence of such behaviour elsewhere in the standard (AFAIK). IMHO
the DR should be changed to make clear that iter_swap it meant to make a
qualified call to std::swap.
The second, independent issue is, whether a qualified call to std::swap
should activate ADL internally, thus finding user-defined swap functions
as if the call would be made through "using std::swap; swap( a, b );".
For iter_swap, the second issue is probably void.
Regards, Daniel
--
Daniel Frey
aixigo AG - financial solutions & technology
Schloß-Rahe-Straße 15, 52072 Aachen, Germany
fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99
eMail: daniel.frey@aixigo.de, web: http://www.aixigo.de