6#ifndef SWIFT_MISC_MIXIN_MIXINCOMPARE_H
7#define SWIFT_MISC_MIXIN_MIXINCOMPARE_H
30 template <
class Derived>
35 friend bool operator==(
const Derived &a,
const Derived &b) {
return compare(a, b) == 0; }
38 friend bool operator!=(
const Derived &a,
const Derived &b) {
return compare(a, b) != 0; }
44 template <
class Derived>
49 friend bool operator==(
const Derived &a,
const Derived &b) {
return equals(a, b); }
52 friend bool operator!=(
const Derived &a,
const Derived &b) {
return !equals(a, b); }
55 static bool equals(
const Derived &a,
const Derived &b);
57 static bool baseEquals(
const T *a,
const T *b);
58 static bool baseEquals(
const void *,
const void *);
60 template <
typename T,
typename Flags>
61 static bool membersEqual(
const T &a,
const T &b, Flags);
64 template <
class Derived>
65 bool EqualsByMetaClass<Derived>::equals(
const Derived &a,
const Derived &b)
72 result = result && EqualsByMetaClass::membersEqual(member.in(a), member.in(b), member.m_flags);
78 template <
class Derived>
80 bool EqualsByMetaClass<Derived>::baseEquals(
const T *a,
const T *b)
85 template <
class Derived>
86 bool EqualsByMetaClass<Derived>::baseEquals(
const void *,
const void *)
91 template <
class Derived>
92 bool EqualsByMetaClass<Derived>::baseEquals(
const CEmpty *,
const CEmpty *)
97 template <
class Derived>
98 template <
typename T,
typename Flags>
99 bool EqualsByMetaClass<Derived>::membersEqual(
const T &a,
const T &b, Flags)
117 template <
class Derived>
122 friend bool operator<(
const Derived &a,
const Derived &b) {
return compare(a, b) < 0; }
125 friend bool operator>(
const Derived &a,
const Derived &b) {
return compare(a, b) > 0; }
128 friend bool operator<=(
const Derived &a,
const Derived &b) {
return compare(a, b) <= 0; }
131 friend bool operator>=(
const Derived &a,
const Derived &b) {
return compare(a, b) >= 0; }
137 template <
class Derived>
142 friend bool operator<(
const Derived &a,
const Derived &b) {
return less(a, b); }
145 friend bool operator>(
const Derived &a,
const Derived &b) {
return less(b, a); }
148 friend bool operator<=(
const Derived &a,
const Derived &b) {
return !less(b, a); }
151 friend bool operator>=(
const Derived &a,
const Derived &b) {
return !less(a, b); }
154 static bool less(
const Derived &a,
const Derived &b);
155 template <
typename T>
156 static bool baseLess(
const T *a,
const T *b);
157 static bool baseLess(
const void *,
const void *);
159 template <
typename T,
typename Flags>
160 static bool membersLess(
bool &io_greaterThan,
const T &a,
const T &b, Flags);
163 template <
class Derived>
164 bool LessThanByMetaClass<Derived>::less(
const Derived &a,
const Derived &b)
172 result = result || LessThanByMetaClass::membersLess(gt, member.in(a), member.in(b), member.m_flags);
178 template <
class Derived>
179 template <
typename T>
180 bool LessThanByMetaClass<Derived>::baseLess(
const T *a,
const T *b)
185 template <
class Derived>
186 bool LessThanByMetaClass<Derived>::baseLess(
const void *,
const void *)
191 template <
class Derived>
192 bool LessThanByMetaClass<Derived>::baseLess(
const CEmpty *,
const CEmpty *)
197 template <
class Derived>
198 template <
typename T,
typename Flags>
199 bool LessThanByMetaClass<Derived>::membersLess(
bool &io_greaterThan,
const T &a,
const T &b, Flags)
212 io_greaterThan = b < a;
220 template <
class Derived>
225 friend int compare(
const Derived &a,
const Derived &b) {
return compareImpl(a, b); }
228 static int compareImpl(
const Derived &a,
const Derived &b);
229 template <
typename T>
230 static int baseCompare(
const T *a,
const T *b);
231 static int baseCompare(
const void *,
const void *);
233 template <
typename T,
typename Flags>
234 static int membersCompare(
const T &a,
const T &b, Flags);
237 template <
class Derived>
238 int CompareByMetaClass<Derived>::compareImpl(
const Derived &a,
const Derived &b)
245 result = result ? result :
246 CompareByMetaClass::membersCompare(member.in(a), member.in(b), member.m_flags);
252 template <
class Derived>
253 template <
typename T>
254 int CompareByMetaClass<Derived>::baseCompare(
const T *a,
const T *b)
259 template <
class Derived>
260 int CompareByMetaClass<Derived>::baseCompare(
const void *,
const void *)
265 template <
class Derived>
266 int CompareByMetaClass<Derived>::baseCompare(
const CEmpty *,
const CEmpty *)
271 template <
class Derived>
272 template <
typename T,
typename Flags>
273 int CompareByMetaClass<Derived>::membersCompare(
const T &a,
const T &b, Flags)
279 else if constexpr (THasCompare<T, T>::value)
285 return a < b ? -1 : b < a ? 1 : 0;
Default base class for CValueObject.
CRTP class template from which a derived class can inherit operator== implemented using its compare f...
friend bool operator!=(const Derived &a, const Derived &b)
Not equal.
friend bool operator==(const Derived &a, const Derived &b)
Equals.
CRTP class template from which a derived class can inherit operator< implemented using its compare fu...
friend bool operator>(const Derived &a, const Derived &b)
Greater than.
friend bool operator<=(const Derived &a, const Derived &b)
Less than or equal.
friend bool operator<(const Derived &a, const Derived &b)
Less than.
friend bool operator>=(const Derived &a, const Derived &b)
Greater than or equal.
int compare(T a, T b)
Compare arithmetic values.
Mixin classes which implement common operations for value classes.
Free functions in swift::misc.
typename TBaseOf< T >::type TBaseOfT
Alias for typename TBaseOf<T>::type.