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 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
9 | |
10 | // <mdspan> |
11 | // |
12 | // template<class OtherIndexType, size_t... OtherExtents> |
13 | // friend constexpr bool operator==(const extents& lhs, |
14 | // const extents<OtherIndexType, OtherExtents...>& rhs) noexcept; |
15 | // |
16 | // Returns: true if lhs.rank() equals rhs.rank() and |
17 | // if lhs.extent(r) equals rhs.extent(r) for every rank index r of rhs, otherwise false. |
18 | // |
19 | |
20 | #include <mdspan> |
21 | #include <type_traits> |
22 | #include <concepts> |
23 | #include <cassert> |
24 | |
25 | #include "test_macros.h" |
26 | |
27 | template <class To, class From> |
28 | constexpr void test_comparison(bool equal, To dest, From src) { |
29 | ASSERT_NOEXCEPT(dest == src); |
30 | assert((dest == src) == equal); |
31 | assert((dest != src) == !equal); |
32 | } |
33 | |
34 | template <class T1, class T2> |
35 | constexpr void test_comparison_different_rank() { |
36 | constexpr size_t D = std::dynamic_extent; |
37 | |
38 | test_comparison(false, std::extents<T1>(), std::extents<T2, D>(1)); |
39 | test_comparison(false, std::extents<T1>(), std::extents<T2, 1>()); |
40 | |
41 | test_comparison(false, std::extents<T1, D>(1), std::extents<T2>()); |
42 | test_comparison(false, std::extents<T1, 1>(), std::extents<T2>()); |
43 | |
44 | test_comparison(false, std::extents<T1, D>(5), std::extents<T2, D, D>(5, 5)); |
45 | test_comparison(false, std::extents<T1, 5>(), std::extents<T2, 5, D>(5)); |
46 | test_comparison(false, std::extents<T1, 5>(), std::extents<T2, 5, 1>()); |
47 | |
48 | test_comparison(false, std::extents<T1, D, D>(5, 5), std::extents<T2, D>(5)); |
49 | test_comparison(false, std::extents<T1, 5, D>(5), std::extents<T2, D>(5)); |
50 | test_comparison(false, std::extents<T1, 5, 5>(), std::extents<T2, 5>()); |
51 | } |
52 | |
53 | template <class T1, class T2> |
54 | constexpr void test_comparison_same_rank() { |
55 | constexpr size_t D = std::dynamic_extent; |
56 | |
57 | test_comparison(true, std::extents<T1>(), std::extents<T2>()); |
58 | |
59 | test_comparison(true, std::extents<T1, D>(5), std::extents<T2, D>(5)); |
60 | test_comparison(true, std::extents<T1, 5>(), std::extents<T2, D>(5)); |
61 | test_comparison(true, std::extents<T1, D>(5), std::extents<T2, 5>()); |
62 | test_comparison(true, std::extents<T1, 5>(), std::extents< T2, 5>()); |
63 | test_comparison(false, std::extents<T1, D>(5), std::extents<T2, D>(7)); |
64 | test_comparison(false, std::extents<T1, 5>(), std::extents<T2, D>(7)); |
65 | test_comparison(false, std::extents<T1, D>(5), std::extents<T2, 7>()); |
66 | test_comparison(false, std::extents<T1, 5>(), std::extents<T2, 7>()); |
67 | |
68 | test_comparison(true, std::extents<T1, D, D, D, D, D>(5, 6, 7, 8, 9), std::extents<T2, D, D, D, D, D>(5, 6, 7, 8, 9)); |
69 | test_comparison(true, std::extents<T1, D, 6, D, 8, D>(5, 7, 9), std::extents<T2, 5, D, D, 8, 9>(6, 7)); |
70 | test_comparison(true, std::extents<T1, 5, 6, 7, 8, 9>(5, 6, 7, 8, 9), std::extents<T2, 5, 6, 7, 8, 9>()); |
71 | test_comparison( |
72 | false, std::extents<T1, D, D, D, D, D>(5, 6, 7, 8, 9), std::extents<T2, D, D, D, D, D>(5, 6, 3, 8, 9)); |
73 | test_comparison(false, std::extents<T1, D, 6, D, 8, D>(5, 7, 9), std::extents<T2, 5, D, D, 3, 9>(6, 7)); |
74 | test_comparison(false, std::extents<T1, 5, 6, 7, 8, 9>(5, 6, 7, 8, 9), std::extents<T2, 5, 6, 7, 3, 9>()); |
75 | } |
76 | |
77 | template <class T1, class T2> |
78 | constexpr void test_comparison() { |
79 | test_comparison_same_rank<T1, T2>(); |
80 | test_comparison_different_rank<T1, T2>(); |
81 | } |
82 | |
83 | constexpr bool test() { |
84 | test_comparison<int, int>(); |
85 | test_comparison<int, size_t>(); |
86 | test_comparison<size_t, int>(); |
87 | test_comparison<size_t, long>(); |
88 | return true; |
89 | } |
90 | |
91 | int main(int, char**) { |
92 | test(); |
93 | static_assert(test()); |
94 | return 0; |
95 | } |
96 | |