compare.pass.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <array>
  9. // These are all constexpr in C++20
  10. // bool operator==(array<T, N> const&, array<T, N> const&);
  11. // bool operator!=(array<T, N> const&, array<T, N> const&);
  12. // bool operator<(array<T, N> const&, array<T, N> const&);
  13. // bool operator<=(array<T, N> const&, array<T, N> const&);
  14. // bool operator>(array<T, N> const&, array<T, N> const&);
  15. // bool operator>=(array<T, N> const&, array<T, N> const&);
  16. #include <array>
  17. #include <vector>
  18. #include <cassert>
  19. #include "test_macros.h"
  20. #include "test_comparisons.h"
  21. // std::array is explicitly allowed to be initialized with A a = { init-list };.
  22. // Disable the missing braces warning for this reason.
  23. #include "disable_missing_braces_warning.h"
  24. int main(int, char**)
  25. {
  26. {
  27. typedef int T;
  28. typedef std::array<T, 3> C;
  29. C c1 = {1, 2, 3};
  30. C c2 = {1, 2, 3};
  31. C c3 = {3, 2, 1};
  32. C c4 = {1, 2, 1};
  33. assert(testComparisons6(c1, c2, true, false));
  34. assert(testComparisons6(c1, c3, false, true));
  35. assert(testComparisons6(c1, c4, false, false));
  36. }
  37. {
  38. typedef int T;
  39. typedef std::array<T, 0> C;
  40. C c1 = {};
  41. C c2 = {};
  42. assert(testComparisons6(c1, c2, true, false));
  43. }
  44. #if TEST_STD_VER > 17
  45. {
  46. constexpr std::array<int, 3> a1 = {1, 2, 3};
  47. constexpr std::array<int, 3> a2 = {2, 3, 4};
  48. static_assert(testComparisons6(a1, a1, true, false), "");
  49. static_assert(testComparisons6(a1, a2, false, true), "");
  50. static_assert(testComparisons6(a2, a1, false, false), "");
  51. }
  52. #endif
  53. return 0;
  54. }