-
Notifications
You must be signed in to change notification settings - Fork 13.6k
WIP [libc++]P2944R3: Constrained comparisions - variant
and tuple
#141396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
a7517fd
ab710f4
dd32d6c
23ebfd7
f862580
ba27f7f
8483790
98b05c4
c64a4ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -268,6 +268,70 @@ struct PartialOrder { | |
} | ||
}; | ||
|
||
#endif | ||
template <typename T1, typename T2 = T1> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess the dependency on the previous PR was due to conflicts in test files. I wonder whether we can make the same additions to the common test files in both PRs, and drop the changes in the the PR merged later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
concept HasOperatorEqual = requires(T1 t1, T2 t2) { t1 == t2; }; | ||
|
||
template <typename T1, typename T2 = T1> | ||
concept HasOperatorGreaterThan = requires(T1 t1, T2 t2) { t1 > t2; }; | ||
|
||
template <typename T1, typename T2 = T1> | ||
concept HasOperatorGreaterThanEqual = requires(T1 t1, T2 t2) { t1 >= t2; }; | ||
template <typename T1, typename T2 = T1> | ||
concept HasOperatorLessThan = requires(T1 t1, T2 t2) { t1 < t2; }; | ||
|
||
template <typename T1, typename T2 = T1> | ||
concept HasOperatorLessThanEqual = requires(T1 t1, T2 t2) { t1 <= t2; }; | ||
|
||
template <typename T1, typename T2 = T1> | ||
concept HasOperatorNotEqual = requires(T1 t1, T2 t2) { t1 != t2; }; | ||
|
||
template <typename T1, typename T2 = T1> | ||
concept HasOperatorSpaceship = requires(T1 t1, T2 t2) { t1 <=> t2; }; | ||
|
||
struct NonComparable {}; | ||
static_assert(!std::equality_comparable<NonComparable>); | ||
static_assert(!HasOperatorEqual<NonComparable>); | ||
static_assert(!HasOperatorGreaterThan<NonComparable>); | ||
static_assert(!HasOperatorGreaterThanEqual<NonComparable>); | ||
static_assert(!HasOperatorLessThan<NonComparable>); | ||
static_assert(!HasOperatorLessThanEqual<NonComparable>); | ||
static_assert(!HasOperatorNotEqual<NonComparable>); | ||
static_assert(!HasOperatorSpaceship<NonComparable>); | ||
|
||
class EqualityComparable { | ||
public: | ||
constexpr EqualityComparable(int value) : value_{value} {}; | ||
|
||
friend constexpr bool operator==(const EqualityComparable&, const EqualityComparable&) noexcept = default; | ||
|
||
private: | ||
int value_; | ||
}; | ||
static_assert(std::equality_comparable<EqualityComparable>); | ||
static_assert(HasOperatorEqual<EqualityComparable>); | ||
static_assert(HasOperatorNotEqual<EqualityComparable>); | ||
|
||
class ThreeWayComparable { | ||
public: | ||
constexpr ThreeWayComparable(int value) : value_{value} {}; | ||
|
||
friend constexpr bool operator==(const ThreeWayComparable&, const ThreeWayComparable&) noexcept = default; | ||
friend constexpr std::strong_ordering | ||
operator<=>(const ThreeWayComparable&, const ThreeWayComparable&) noexcept = default; | ||
|
||
private: | ||
int value_; | ||
}; | ||
static_assert(std::equality_comparable<ThreeWayComparable>); | ||
static_assert(std::three_way_comparable<ThreeWayComparable>); | ||
static_assert(HasOperatorEqual<ThreeWayComparable>); | ||
static_assert(HasOperatorGreaterThan<ThreeWayComparable>); | ||
static_assert(HasOperatorGreaterThanEqual<ThreeWayComparable>); | ||
static_assert(HasOperatorLessThan<ThreeWayComparable>); | ||
static_assert(HasOperatorLessThanEqual<ThreeWayComparable>); | ||
static_assert(HasOperatorNotEqual<ThreeWayComparable>); | ||
static_assert(HasOperatorSpaceship<ThreeWayComparable>); | ||
|
||
#endif // TEST_STD_VER >= 20 | ||
|
||
#endif // TEST_COMPARISONS_H |
Uh oh!
There was an error while loading. Please reload this page.