max.pass.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <algorithm>
  10. // template<LessThanComparable T>
  11. // const T&
  12. // max(const T& a, const T& b);
  13. #include <algorithm>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. template <class T>
  17. void
  18. test(const T& a, const T& b, const T& x)
  19. {
  20. assert(&std::max(a, b) == &x);
  21. }
  22. int main()
  23. {
  24. {
  25. int x = 0;
  26. int y = 0;
  27. test(x, y, x);
  28. test(y, x, y);
  29. }
  30. {
  31. int x = 0;
  32. int y = 1;
  33. test(x, y, y);
  34. test(y, x, y);
  35. }
  36. {
  37. int x = 1;
  38. int y = 0;
  39. test(x, y, x);
  40. test(y, x, x);
  41. }
  42. #if TEST_STD_VER >= 14
  43. {
  44. constexpr int x = 1;
  45. constexpr int y = 0;
  46. static_assert(std::max(x, y) == x, "" );
  47. static_assert(std::max(y, x) == x, "" );
  48. }
  49. #endif
  50. }