This is a good way to get close to it. It is as effective as you. I doubt that this particular function has a universally recognized name. This is apparently called compare-swap.
Summarizing it by type is as simple as:
template <typename T>
void ascending(T& dFirst, T& dSecond)
{
if (dFirst > dSecond)
std::swap(dFirst, dSecond);
}
:
int main() {
int a=10, b=5;
ascending(a, b);
std::cout << a << ", " << b << std::endl;
double c=7.2, d=3.1;
ascending(c, d);
std::cout << c << ", " << d << std::endl;
return 0;
}
:
5, 10
3.1, 7.2