1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
13 // template<class OtherExtents>
14 // friend constexpr bool operator==(const mapping& x, const mapping<OtherExtents>& y) noexcept;
16 // Constraints: extents_type::rank() == OtherExtents::rank() is true.
19 #include <type_traits>
23 #include "test_macros.h"
25 template <class To
, class From
>
26 constexpr void test_comparison(bool equal
, To dest_exts
, From src_exts
) {
27 std::layout_right::mapping
<To
> dest(dest_exts
);
28 std::layout_right::mapping
<From
> src(src_exts
);
29 ASSERT_NOEXCEPT(dest
== src
);
30 assert((dest
== src
) == equal
);
31 assert((dest
!= src
) == !equal
);
35 constexpr bool does_not_match() { return true; }
38 constexpr X
compare_layout_mappings(...) { return {}; }
40 template <class E1
, class E2
>
41 constexpr auto compare_layout_mappings(E1 e1
, E2 e2
)
42 -> decltype(std::layout_right::mapping
<E1
>(e1
) == std::layout_right::mapping
<E2
>(e2
)) {
46 template <class T1
, class T2
>
47 constexpr void test_comparison_different_rank() {
48 constexpr size_t D
= std::dynamic_extent
;
50 // sanity check same rank
51 static_assert(compare_layout_mappings(std::extents
<T1
, D
>(5), std::extents
<T2
, D
>(5)));
52 static_assert(compare_layout_mappings(std::extents
<T1
, 5>(), std::extents
<T2
, D
>(5)));
53 static_assert(compare_layout_mappings(std::extents
<T1
, D
>(5), std::extents
<T2
, 5>()));
54 static_assert(compare_layout_mappings(std::extents
<T1
, 5>(), std::extents
<T2
, 5>()));
56 // not equality comparable when rank is not the same
57 static_assert(compare_layout_mappings(std::extents
<T1
>(), std::extents
<T2
, D
>(1)).does_not_match());
58 static_assert(compare_layout_mappings(std::extents
<T1
>(), std::extents
<T2
, 1>()).does_not_match());
60 static_assert(compare_layout_mappings(std::extents
<T1
, D
>(1), std::extents
<T2
>()).does_not_match());
61 static_assert(compare_layout_mappings(std::extents
<T1
, 1>(), std::extents
<T2
>()).does_not_match());
63 static_assert(compare_layout_mappings(std::extents
<T1
, D
>(5), std::extents
<T2
, D
, D
>(5, 5)).does_not_match());
64 static_assert(compare_layout_mappings(std::extents
<T1
, 5>(), std::extents
<T2
, 5, D
>(5)).does_not_match());
65 static_assert(compare_layout_mappings(std::extents
<T1
, 5>(), std::extents
<T2
, 5, 1>()).does_not_match());
67 static_assert(compare_layout_mappings(std::extents
<T1
, D
, D
>(5, 5), std::extents
<T2
, D
>(5)).does_not_match());
68 static_assert(compare_layout_mappings(std::extents
<T1
, 5, D
>(5), std::extents
<T2
, D
>(5)).does_not_match());
69 static_assert(compare_layout_mappings(std::extents
<T1
, 5, 5>(), std::extents
<T2
, 5>()).does_not_match());
72 template <class T1
, class T2
>
73 constexpr void test_comparison_same_rank() {
74 constexpr size_t D
= std::dynamic_extent
;
76 test_comparison(true, std::extents
<T1
>(), std::extents
<T2
>());
78 test_comparison(true, std::extents
<T1
, D
>(5), std::extents
<T2
, D
>(5));
79 test_comparison(true, std::extents
<T1
, 5>(), std::extents
<T2
, D
>(5));
80 test_comparison(true, std::extents
<T1
, D
>(5), std::extents
<T2
, 5>());
81 test_comparison(true, std::extents
<T1
, 5>(), std::extents
< T2
, 5>());
82 test_comparison(false, std::extents
<T1
, D
>(5), std::extents
<T2
, D
>(7));
83 test_comparison(false, std::extents
<T1
, 5>(), std::extents
<T2
, D
>(7));
84 test_comparison(false, std::extents
<T1
, D
>(5), std::extents
<T2
, 7>());
85 test_comparison(false, std::extents
<T1
, 5>(), std::extents
<T2
, 7>());
87 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));
88 test_comparison(true, std::extents
<T1
, D
, 6, D
, 8, D
>(5, 7, 9), std::extents
<T2
, 5, D
, D
, 8, 9>(6, 7));
89 test_comparison(true, std::extents
<T1
, 5, 6, 7, 8, 9>(5, 6, 7, 8, 9), std::extents
<T2
, 5, 6, 7, 8, 9>());
91 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));
92 test_comparison(false, std::extents
<T1
, D
, 6, D
, 8, D
>(5, 7, 9), std::extents
<T2
, 5, D
, D
, 3, 9>(6, 7));
93 test_comparison(false, std::extents
<T1
, 5, 6, 7, 8, 9>(5, 6, 7, 8, 9), std::extents
<T2
, 5, 6, 7, 3, 9>());
96 template <class T1
, class T2
>
97 constexpr void test_comparison() {
98 test_comparison_same_rank
<T1
, T2
>();
99 test_comparison_different_rank
<T1
, T2
>();
102 constexpr bool test() {
103 test_comparison
<int, int>();
104 test_comparison
<int, size_t>();
105 test_comparison
<size_t, int>();
106 test_comparison
<size_t, long>();
110 int main(int, char**) {
112 static_assert(test());