In C++20, there are two swap
function templates: std::ranges::swap(T&&, U&&)
and std::swap(T&, T&)
.
I just wonder:
What's the difference between they two?
In rough terms: std::ranges::swap
generalizes std::swap
.
T
and U
are the same, then it's equivalent to invoking std::swap
.See the cppreference page for details.
I must say I find this function to be somewhat confusing and baroque, but then - maybe people more experienced with the range library develop an intuition as to why it makes sense.