//===----------------------------------------------------------------------===// // // 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_with = // see below #include #include "compare_types.h" template constexpr bool check_three_way_comparable_with() { constexpr bool result = std::three_way_comparable_with; static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); if constexpr (!std::is_void_v) { static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); static_assert(std::three_way_comparable_with == result); } return result; } namespace fundamentals { static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); struct S {}; static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); static_assert(!check_three_way_comparable_with()); } // namespace fundamentals namespace user_defined { struct S { bool operator==(int) const; std::strong_ordering operator<=>(int) const; operator int() const; bool operator==(const S&) const = default; auto operator<=>(const S&) const = default; }; static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); static_assert(check_three_way_comparable_with()); struct SpaceshipNotDeclared { }; static_assert(!check_three_way_comparable_with()); struct SpaceshipDeleted { auto operator<=>(const SpaceshipDeleted&) const = delete; }; static_assert(!check_three_way_comparable_with()); struct SpaceshipWithoutEqualityOperator { auto operator<=>(const SpaceshipWithoutEqualityOperator&) const; }; static_assert(!check_three_way_comparable_with()); struct EqualityOperatorDeleted { bool operator==(const EqualityOperatorDeleted&) const = delete; }; static_assert(!check_three_way_comparable_with()); struct EqualityOperatorOnly { bool operator==(const EqualityOperatorOnly&) const = default; }; static_assert(!check_three_way_comparable_with()); struct SpaceshipDeclaredEqualityOperatorDeleted { bool operator==(const SpaceshipDeclaredEqualityOperatorDeleted&) const = delete; auto operator<=>(const SpaceshipDeclaredEqualityOperatorDeleted&) const = default; }; static_assert(!check_three_way_comparable_with()); 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(!check_three_way_comparable_with()); 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(!check_three_way_comparable_with()); struct AllButOneInequalityOperators { bool operator<(const AllButOneInequalityOperators&) const; bool operator<=(const AllButOneInequalityOperators&) const; bool operator>(const AllButOneInequalityOperators&) const; bool operator!=(const AllButOneInequalityOperators&) const; }; static_assert(!check_three_way_comparable_with()); 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(!check_three_way_comparable_with()); struct EqualityOperatorWrongReturnType { int operator==(const EqualityOperatorWrongReturnType&); auto operator<=>(const EqualityOperatorWrongReturnType&) const = default; }; static_assert(!check_three_way_comparable_with()); struct SpaceshipWrongReturnType { bool operator==(const SpaceshipWrongReturnType&) const = default; int operator<=>(const SpaceshipWrongReturnType&); }; static_assert(!check_three_way_comparable_with()); struct EqualityOperatorNonConstArgument { bool operator==(EqualityOperatorNonConstArgument&); auto operator<=>(const EqualityOperatorNonConstArgument&) const = default; }; static_assert(!check_three_way_comparable_with()); struct SpaceshipNonConstArgument { bool operator==(const SpaceshipNonConstArgument&) const = default; auto operator<=>(SpaceshipNonConstArgument&); }; static_assert(!check_three_way_comparable_with()); } // namespace user_defined