Re:Clang emits memcpy for std::swap, which can introduce und...
by dkopi on Sunday April 24, 2016 @04:22PM
(#11561204)
Imagine reversing a string:
If swap doesn't work for a self swap, this code would break in the case of an odd length string.
It's an easy fix in this case, but being able to swap an element with itself is convenient.
[ Parent
| on HN ]
Re:Clang emits memcpy for std::swap, which can introduce und...
by Matheus28 on Sunday April 24, 2016 @04:55PM
(#11561338)
A more common case, would be swapping a vector element with the back of the vector and popping it off, which is kinda common.
Re:Clang emits memcpy for std::swap, which can introduce und...
by plorkyeran on Sunday April 24, 2016 @05:54PM
(#11561538)
It was common pre-C++11, but these days you should just be doing a move and pop rather than a swap and pop.