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 <cassert>
21#include <cstddef>
22#include <mdspan>
23
24#include "test_macros.h"
25
26template <class To, class From>
27constexpr void test_comparison(bool equal, To dest, From src) {
28 ASSERT_NOEXCEPT(dest == src);
29 assert((dest == src) == equal);
30 assert((dest != src) == !equal);
31}
32
33template <class T1, class T2>
34constexpr void test_comparison_different_rank() {
35 constexpr size_t D = std::dynamic_extent;
36
37 test_comparison(false, std::extents<T1>(), std::extents<T2, D>(1));
38 test_comparison(false, std::extents<T1>(), std::extents<T2, 1>());
39
40 test_comparison(false, std::extents<T1, D>(1), std::extents<T2>());
41 test_comparison(false, std::extents<T1, 1>(), std::extents<T2>());
42
43 test_comparison(false, std::extents<T1, D>(5), std::extents<T2, D, D>(5, 5));
44 test_comparison(false, std::extents<T1, 5>(), std::extents<T2, 5, D>(5));
45 test_comparison(false, std::extents<T1, 5>(), std::extents<T2, 5, 1>());
46
47 test_comparison(false, std::extents<T1, D, D>(5, 5), std::extents<T2, D>(5));
48 test_comparison(false, std::extents<T1, 5, D>(5), std::extents<T2, D>(5));
49 test_comparison(false, std::extents<T1, 5, 5>(), std::extents<T2, 5>());
50}
51
52template <class T1, class T2>
53constexpr void test_comparison_same_rank() {
54 constexpr size_t D = std::dynamic_extent;
55
56 test_comparison(true, std::extents<T1>(), std::extents<T2>());
57
58 test_comparison(true, std::extents<T1, D>(5), std::extents<T2, D>(5));
59 test_comparison(true, std::extents<T1, 5>(), std::extents<T2, D>(5));
60 test_comparison(true, std::extents<T1, D>(5), std::extents<T2, 5>());
61 test_comparison(true, std::extents<T1, 5>(), std::extents< T2, 5>());
62 test_comparison(false, std::extents<T1, D>(5), std::extents<T2, D>(7));
63 test_comparison(false, std::extents<T1, 5>(), std::extents<T2, D>(7));
64 test_comparison(false, std::extents<T1, D>(5), std::extents<T2, 7>());
65 test_comparison(false, std::extents<T1, 5>(), std::extents<T2, 7>());
66
67 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));
68 test_comparison(true, std::extents<T1, D, 6, D, 8, D>(5, 7, 9), std::extents<T2, 5, D, D, 8, 9>(6, 7));
69 test_comparison(true, std::extents<T1, 5, 6, 7, 8, 9>(5, 6, 7, 8, 9), std::extents<T2, 5, 6, 7, 8, 9>());
70 test_comparison(
71 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));
72 test_comparison(false, std::extents<T1, D, 6, D, 8, D>(5, 7, 9), std::extents<T2, 5, D, D, 3, 9>(6, 7));
73 test_comparison(false, std::extents<T1, 5, 6, 7, 8, 9>(5, 6, 7, 8, 9), std::extents<T2, 5, 6, 7, 3, 9>());
74}
75
76template <class T1, class T2>
77constexpr void test_comparison() {
78 test_comparison_same_rank<T1, T2>();
79 test_comparison_different_rank<T1, T2>();
80}
81
82constexpr bool test() {
83 test_comparison<int, int>();
84 test_comparison<int, size_t>();
85 test_comparison<size_t, int>();
86 test_comparison<size_t, long>();
87 return true;
88}
89
90int main(int, char**) {
91 test();
92 static_assert(test());
93 return 0;
94}
95

source code of libcxx/test/std/containers/views/mdspan/extents/comparison.pass.cpp