fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <tuple>
  4.  
  5. int main() {
  6. int a, b;
  7.  
  8. a = 6;
  9. b = 5;
  10.  
  11. auto p = std::minmax(a, b);
  12. std::cout << "p.first = " << p.first << std::endl;
  13. std::cout << "p.second = " << p.second << std::endl;
  14.  
  15. a = 5;
  16. b = 6;
  17.  
  18. std::tie(b, a) = std::minmax(a, b);
  19.  
  20. std::cout << "a = " << a << std::endl;
  21. std::cout << "b = " << b << std::endl;
  22.  
  23. a = 5;
  24. b = 6;
  25.  
  26. std::tie(b, a) = std::minmax({a, b});
  27.  
  28. std::cout << "a = " << a << std::endl;
  29. std::cout << "b = " << b << std::endl;
  30. }
  31.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
p.first = 5
p.second = 6
a = 5
b = 5
a = 6
b = 5