//===----------------------------------------------------------------------===// // // 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 // template // concept three_way_comparable = // see below #include #include "compare_types.h" #include "test_macros.h" namespace fundamentals { // with default ordering static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); #ifndef TEST_HAS_NO_CHAR8_T static_assert(std::three_way_comparable); #endif static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); #ifndef TEST_HAS_NO_INT128 static_assert(std::three_way_comparable<__int128_t const&>); static_assert(std::three_way_comparable<__uint128_t const&>); #endif static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); // with explicit ordering static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); struct S {}; static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); static_assert(!std::three_way_comparable); } // namespace fundamentals namespace user_defined { struct S { auto operator<=>(const S&) const = default; }; static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); static_assert(std::three_way_comparable); struct SpaceshipNotDeclared { }; static_assert(!std::three_way_comparable); struct SpaceshipDeleted { auto operator<=>(const SpaceshipDeleted&) const = delete; }; static_assert(!std::three_way_comparable); struct SpaceshipWithoutEqualityOperator { auto operator<=>(const SpaceshipWithoutEqualityOperator&) const; }; static_assert(!std::three_way_comparable); struct EqualityOperatorDeleted { bool operator==(const EqualityOperatorDeleted&) const = delete; }; static_assert(!std::three_way_comparable); struct EqualityOperatorOnly { bool operator==(const EqualityOperatorOnly&) const = default; }; static_assert(!std::three_way_comparable); struct SpaceshipDeclaredEqualityOperatorDeleted { bool operator==(const SpaceshipDeclaredEqualityOperatorDeleted&) const = delete; auto operator<=>(const SpaceshipDeclaredEqualityOperatorDeleted&) const = default; }; static_assert(!std::three_way_comparable); struct AllInequalityOperators { bool operator<(const AllInequalityOperators&) const; bool operator<=(const AllInequalityOperators&) const; bool operator>(const AllInequalityOperators&) const; bool operator>=(const AllInequalityOperators&) const; bool operator!=(const AllInequalityOperators&) const; }; static_assert(!std::three_way_comparable); struct AllComparisonOperators { bool operator<(const AllComparisonOperators&) const; bool operator<=(const AllComparisonOperators&) const; bool operator>(const AllComparisonOperators&) const; bool operator>=(const AllComparisonOperators&) const; bool operator!=(const AllComparisonOperators&) const; bool operator==(const AllComparisonOperators&) const; }; static_assert(!std::three_way_comparable); struct AllButOneInequalityOperators { bool operator<(const AllButOneInequalityOperators&) const; bool operator<=(const AllButOneInequalityOperators&) const; bool operator>(const AllButOneInequalityOperators&) const; bool operator!=(const AllButOneInequalityOperators&) const; }; static_assert(!std::three_way_comparable); struct AllInequalityOperatorsOneDeleted { bool operator<(const AllInequalityOperatorsOneDeleted&) const; bool operator<=(const AllInequalityOperatorsOneDeleted&) const; bool operator>(const AllInequalityOperatorsOneDeleted&) const; bool operator>=(const AllInequalityOperatorsOneDeleted&) const = delete; bool operator!=(const AllInequalityOperatorsOneDeleted&) const; }; static_assert(!std::three_way_comparable); struct EqualityOperatorWrongReturnType { int operator==(const EqualityOperatorWrongReturnType&); auto operator<=>(const EqualityOperatorWrongReturnType&) const = default; }; static_assert(!std::three_way_comparable); struct SpaceshipWrongReturnType { bool operator==(const SpaceshipWrongReturnType&) const = default; int operator<=>(const SpaceshipWrongReturnType&); }; static_assert(!std::three_way_comparable); struct EqualityOperatorNonConstArgument { bool operator==(EqualityOperatorNonConstArgument&); auto operator<=>(const EqualityOperatorNonConstArgument&) const = default; }; static_assert(!std::three_way_comparable); struct SpaceshipNonConstArgument { bool operator==(const SpaceshipNonConstArgument&) const = default; auto operator<=>(SpaceshipNonConstArgument&); }; static_assert(!std::three_way_comparable); } // namespace user_defined