Re:Hoare’s Rebuttal and Bubble Sort’s Comeback
by CJefferson on Sunday January 30, 2022 @12:29PM
(#30139078)
As integers are "movable" (moving them in C++ just copies them, but you can call std::move), implementations of algorithms like std::sort tend to assume they are only allowed to move things.
You could in principle write two implementations, one that moves + swaps, and one that moves, swaps and (occasionally if it really wants to) copies, but it's extremely hard (possibly impossible) to decide when it is "safe" to use the std::sort that can copy.
It turns out it is much easier to optimise if you can copy the pivot into a local variable, but that's hard to do in std::sort.
Re:Hoare’s Rebuttal and Bubble Sort’s Comeback
by vlovich123 on Sunday January 30, 2022 @12:44PM
(#30139254)
I don’t follow. is_copy_constructible tells you if you can copy the type…
Re:Hoare’s Rebuttal and Bubble Sort’s Comeback
by CJefferson on Sunday January 30, 2022 @02:41PM
(#30140379)
Sometimes it produces the wrong answer, see for example https://devblogs.microsoft.com/oldnewthing/20190926-00/?p=10... (things may have gotten better since C++11, I haven't kept up with the times!)
Do you mean internally/due to subtle complexity requirements? Cause std::sort works just fine on copyable types like integers and complexity is only defined in terms of swaps.