The problem is that std::minmax() takes two links and returns a couple of links. In particular, in your case, it will return a pair, where the first element is a link to x2 , and the second element is a link to x1 .
On the left side of the assignment, on the other hand, you have:
std::tie(x1, x2)
Which also creates a pair of links (normal, a tuple of two links actually, but that doesn't matter), but this time the first element of the pair is a link to x1 , and the second element is a link to x2 .
Then you assign the pair returned by std::minmax() to the pair returned by std::tie , which means that x1 first gets the value x2 (which is 1 ); then x2 gets the new value x1 (again, because std::minmax() returned a pair of links, so the second element of this pair βseesβ the side effect of assigning to x1 ), which is now 1 .
This should explain the conclusion.
source share