//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 // // template // friend constexpr bool operator==(const mapping& x, const mapping& y) noexcept; // ` // Constraints: extents_type::rank() == OtherExtents::rank() is true. #include #include #include #include // dynamic_extent #include "test_macros.h" template constexpr void test_comparison(bool equal, To dest_exts, From src_exts) { std::layout_right::mapping dest(dest_exts); std::layout_right::mapping src(src_exts); ASSERT_NOEXCEPT(dest == src); assert((dest == src) == equal); assert((dest != src) == !equal); } struct X { constexpr bool does_not_match() { return true; } }; constexpr X compare_layout_mappings(...) { return {}; } template constexpr auto compare_layout_mappings(E1 e1, E2 e2) -> decltype(std::layout_right::mapping(e1) == std::layout_right::mapping(e2)) { return true; } template constexpr void test_comparison_different_rank() { constexpr size_t D = std::dynamic_extent; // sanity check same rank static_assert(compare_layout_mappings(std::extents(5), std::extents(5))); static_assert(compare_layout_mappings(std::extents(), std::extents(5))); static_assert(compare_layout_mappings(std::extents(5), std::extents())); static_assert(compare_layout_mappings(std::extents(), std::extents())); // not equality comparable when rank is not the same static_assert(compare_layout_mappings(std::extents(), std::extents(1)).does_not_match()); static_assert(compare_layout_mappings(std::extents(), std::extents()).does_not_match()); static_assert(compare_layout_mappings(std::extents(1), std::extents()).does_not_match()); static_assert(compare_layout_mappings(std::extents(), std::extents()).does_not_match()); static_assert(compare_layout_mappings(std::extents(5), std::extents(5, 5)).does_not_match()); static_assert(compare_layout_mappings(std::extents(), std::extents(5)).does_not_match()); static_assert(compare_layout_mappings(std::extents(), std::extents()).does_not_match()); static_assert(compare_layout_mappings(std::extents(5, 5), std::extents(5)).does_not_match()); static_assert(compare_layout_mappings(std::extents(5), std::extents(5)).does_not_match()); static_assert(compare_layout_mappings(std::extents(), std::extents()).does_not_match()); } template constexpr void test_comparison_same_rank() { constexpr size_t D = std::dynamic_extent; test_comparison(true, std::extents(), std::extents()); test_comparison(true, std::extents(5), std::extents(5)); test_comparison(true, std::extents(), std::extents(5)); test_comparison(true, std::extents(5), std::extents()); test_comparison(true, std::extents(), std::extents< T2, 5>()); test_comparison(false, std::extents(5), std::extents(7)); test_comparison(false, std::extents(), std::extents(7)); test_comparison(false, std::extents(5), std::extents()); test_comparison(false, std::extents(), std::extents()); test_comparison(true, std::extents(5, 6, 7, 8, 9), std::extents(5, 6, 7, 8, 9)); test_comparison(true, std::extents(5, 7, 9), std::extents(6, 7)); test_comparison(true, std::extents(5, 6, 7, 8, 9), std::extents()); test_comparison( false, std::extents(5, 6, 7, 8, 9), std::extents(5, 6, 3, 8, 9)); test_comparison(false, std::extents(5, 7, 9), std::extents(6, 7)); test_comparison(false, std::extents(5, 6, 7, 8, 9), std::extents()); } template constexpr void test_comparison() { test_comparison_same_rank(); test_comparison_different_rank(); } constexpr bool test() { test_comparison(); test_comparison(); test_comparison(); test_comparison(); return true; } int main(int, char**) { test(); static_assert(test()); return 0; }