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