minmax_comp.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <algorithm>
  10. // template<class T, StrictWeakOrder<auto, T> Compare>
  11. // requires !SameType<T, Compare> && CopyConstructible<Compare>
  12. // pair<const T&, const T&>
  13. // minmax(const T& a, const T& b, Compare comp);
  14. #include <algorithm>
  15. #include <functional>
  16. #include <cassert>
  17. template <class T, class C>
  18. void
  19. test(const T& a, const T& b, C c, const T& x, const T& y)
  20. {
  21. std::pair<const T&, const T&> p = std::minmax(a, b, c);
  22. assert(&p.first == &x);
  23. assert(&p.second == &y);
  24. }
  25. int main()
  26. {
  27. {
  28. int x = 0;
  29. int y = 0;
  30. test(x, y, std::greater<int>(), x, y);
  31. test(y, x, std::greater<int>(), y, x);
  32. }
  33. {
  34. int x = 0;
  35. int y = 1;
  36. test(x, y, std::greater<int>(), y, x);
  37. test(y, x, std::greater<int>(), y, x);
  38. }
  39. {
  40. int x = 1;
  41. int y = 0;
  42. test(x, y, std::greater<int>(), x, y);
  43. test(y, x, std::greater<int>(), x, y);
  44. }
  45. }