This is the mail archive of the
mailing list for the libstdc++ project.
Re: Why doesn't iter_swap use swap?
Hello self :)
Just to pad out my earlier mail, it looks like intel's implementation
does use swap to implement iter_swap, and stlport's implementation
requires the two parameters to iter_swap must have the same type (unlike
There is also a defect report against iter_swap (
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html , defect
187 ), which discusses how to be honest it's a bit of a mess.
I see this has been previously posted about but wasn't discussed in
depth. However for performing STL algorithms in constructs of any kind
of complexity I imagine this is causing some serious dents in performance.
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
The "new" iter_swap will also not work in cases where the two
iterators' value_types are distinct types:
std::iter_swap (&i, &d);
I suppose iter_swap may not have been intended to work with such
iterators but I don't see any requirement that the two types be
the same, so the resolution breaks code written to exploit this
capability. (Our implementation of iter_swap allows heterogeneous
I would like to see the standard changed to either explicitly
require that iter_swap's iterators' value_types be identical
or the resolution of issue 187 reverted/changed so as not to
force this new requirement.