P2187R5: std::swap_if, std::predictable


This paper proposes new Standard Library primitives swap_if and iter_swap_if, currently used implicitly (but deeply sub-optimally) in nearly half of the Standard Library algorithms, and equally useful for users’ algorithms. Although trivial to code correctly, current shipping compilers generate markedly sub-optimal code for naïve implementations.

In addition, it proposes a means to indicate to Standard Library facilities that the results of an ordering predicate in a particular use have turned out to be predictable, so that a more appropriate variant of the algorithm may be substituted. Finally, it defines a customization point to identify types with non-trivial special members that nonetheless qualify for optimization.


Stay in touch