//===----------------------------------------------------------------------===// // // 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 // //===----------------------------------------------------------------------===// // // template class tuple; // template // bool // operator==(const tuple& t, const tuple& u); // template // friend constexpr bool operator==(const tuple& t, const UTuple& u); // since C++23 // UNSUPPORTED: c++03 #include #include #include #include "test_comparisons.h" #include "test_macros.h" #if TEST_STD_VER >= 23 # include #endif #if TEST_STD_VER >= 26 # include #endif #if TEST_STD_VER >= 26 // Test SFINAE. static_assert(std::equality_comparable>); static_assert(std::equality_comparable>); static_assert(!std::equality_comparable>); static_assert(!std::equality_comparable>); static_assert(!std::equality_comparable>); static_assert(!std::equality_comparable_with, std::tuple>); static_assert(!std::equality_comparable_with, std::tuple>); // Size mismatch. static_assert( !std::equality_comparable_with, std::tuple>); static_assert( !std::equality_comparable_with, std::tuple>); // Heterogeneous comparisons. // TODO: Use equality_comparable_with once other changes of tuple introduced in P2165R4 are implemented. template concept can_eq_compare = requires(const T& t, const U& u) { t == u; }; static_assert(can_eq_compare, std::array>); static_assert(!can_eq_compare, std::array>); static_assert(can_eq_compare, std::pair>); static_assert( !can_eq_compare, std::pair>); static_assert(can_eq_compare, std::ranges::subrange>); static_assert(!can_eq_compare, std::ranges::subrange>); static_assert(can_eq_compare, std::complex>); static_assert(!can_eq_compare, std::complex>); // Size mismatch in heterogeneous comparisons. static_assert(!can_eq_compare, std::array>); static_assert(!can_eq_compare, std::array>); static_assert(!can_eq_compare, std::pair>); static_assert(!can_eq_compare, std::pair>); static_assert(!can_eq_compare, std::ranges::subrange>); static_assert(!can_eq_compare, std::complex>); #endif TEST_CONSTEXPR_CXX14 bool test() { { typedef std::tuple<> T1; typedef std::tuple<> T2; const T1 t1; const T2 t2; assert(t1 == t2); assert(!(t1 != t2)); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1); const T2 t2(1.1); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1); const T2 t2(1); assert(t1 == t2); assert(!(t1 != t2)); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2); const T2 t2(1, 2); assert(t1 == t2); assert(!(t1 != t2)); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2); const T2 t2(1, 3); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2); const T2 t2(1.1, 2); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2); const T2 t2(1.1, 3); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1, 2, 3); assert(t1 == t2); assert(!(t1 != t2)); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1.1, 2, 3); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1, 3, 3); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1, 2, 4); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1, 3, 2); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1.1, 2, 2); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1.1, 3, 3); assert(!(t1 == t2)); assert(t1 != t2); } { typedef std::tuple T1; typedef std::tuple T2; const T1 t1(1, 2, 3); const T2 t2(1.1, 3, 2); assert(!(t1 == t2)); assert(t1 != t2); } #if TEST_STD_VER >= 14 { using T1 = std::tuple; using T2 = std::tuple; constexpr T1 t1(1, 2, 3); constexpr T2 t2(1.1, 3, 2); assert(!(t1 == t2)); assert(t1 != t2); } #endif #if TEST_STD_VER >= 23 { using T1 = std::tuple; using T2 = std::pair; constexpr T1 t1{1, 2}; constexpr T2 t2{1.0, 2}; assert(t1 == t2); assert(!(t1 != t2)); } { using T1 = std::tuple; using T2 = std::pair; constexpr T1 t1{1, 2}; constexpr T2 t2{1.1, 3}; assert(!(t1 == t2)); assert(t1 != t2); } { using T1 = std::tuple; using T2 = std::array; constexpr T1 t1{1, 2}; constexpr T2 t2{1.0, 2.0}; assert(t1 == t2); assert(!(t1 != t2)); } { using T1 = std::tuple; using T2 = std::array; constexpr T1 t1{1, 2}; constexpr T2 t2{1.1, 3.0}; assert(!(t1 == t2)); assert(t1 != t2); } { using T1 = std::tuple; using T2 = std::ranges::subrange; int arr[1]{}; T1 t1{arr, arr + 1}; T2 t2{arr}; assert(t1 == t2); assert(!(t1 != t2)); } { using T1 = std::tuple; using T2 = std::ranges::subrange; int arr[1]{}; T1 t1{arr, arr}; T2 t2{arr}; assert(!(t1 == t2)); assert(t1 != t2); } { assert((std::tuple<>{} == std::array{})); assert((std::tuple<>{} == std::array{})); } #endif #if TEST_STD_VER >= 26 { using T1 = std::tuple; using T2 = std::complex; constexpr T1 t1{1, 2}; constexpr T2 t2{1.0, 2.0}; assert(t1 == t2); assert(!(t1 != t2)); } { using T1 = std::tuple; using T2 = std::complex; constexpr T1 t1{1, 2}; constexpr T2 t2{1.1, 3.0}; assert(!(t1 == t2)); assert(t1 != t2); } #endif return true; } int main(int, char**) { test(); #if TEST_STD_VER >= 14 static_assert(test(), ""); #endif return 0; }