swap
should be used in preference toiter_swap
, which was included in the C++ Standard for backward compatibility.
But comp.std.c++ says:
Most STL algorithms operate on iterator ranges. It therefore makes sense to use
iter_swap
when swapping elements within those ranges, since that is its intended purpose --- swapping the elements pointed to by two iterators. This allows optimizations for node-based sequences such asstd::list
, whereby the nodes are just relinked, rather than the data actually being swapped.
So which one is correct? Should I use iter_swap
, or should I use swap
? (Is iter_swap
only for backwards compatibility?) Why?