Why doesn't iter_swap use swap?

chris caj@cs.york.ac.uk
Sun Aug 22 09:07:00 GMT 2004


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 
the standard).

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 
places.

I'm happy to continue investigating this, but I suspect someone else 
might be able to advise quickly what is going on. If it turns out that 
we can't or won't change iter_swap in general, then a large number of 
overloads may have to be defined as at the moment many algorithms are 
not using swap and are therefore much more expensive than they should be.

Chris



More information about the Libstdc++ mailing list