std::tie(a, b) = std::minmax(a, b);
I think this is intuitive code. Clean and understandable. Too bad it doesn\'t work as intended, as std::minmax temp
Sometimes, taking a step back and finding a different way pays off:
if (b < a)
std::iter_swap(&a, &b);
That's concise and generally more efficient, certainly at least on par. Maybe pack it into its own function:
template
void reorder(T& a, T& b)
noexcept(noexcept(b < a, void(), std::iter_swap(&a, &b))) {
if (b < a)
std::iter_swap(&a, &b);
}
I'm using std::iter_swap() so I don't have to use the using std::swap; swap(a, b)
two-step for generality in pre-C++2a, which introduces customization point objects making that obsolete.