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)
69 introspect<Derived>().forEachMember([&](
auto member) {
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)
103 return a.compare(b, Qt::CaseInsensitive) == 0;
105 else {
return a == b; }
114 template <
class Derived>
119 friend bool operator<(
const Derived &a,
const Derived &b) {
return compare(a, b) < 0; }
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; }
134 template <
class Derived>
139 friend bool operator<(
const Derived &a,
const Derived &b) {
return less(a, b); }
142 friend bool operator>(
const Derived &a,
const Derived &b) {
return less(b, a); }
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(a, b); }
151 static bool less(
const Derived &a,
const Derived &b);
152 template <
typename T>
153 static bool baseLess(
const T *a,
const T *b);
154 static bool baseLess(
const void *,
const void *);
156 template <
typename T,
typename Flags>
157 static bool membersLess(
bool &io_greaterThan,
const T &a,
const T &b, Flags);
160 template <
class Derived>
161 bool LessThanByMetaClass<Derived>::less(
const Derived &a,
const Derived &b)
166 introspect<Derived>().forEachMember([&](
auto member) {
169 result = result || LessThanByMetaClass::membersLess(gt, member.in(a), member.in(b), member.m_flags);
175 template <
class Derived>
176 template <
typename T>
177 bool LessThanByMetaClass<Derived>::baseLess(
const T *a,
const T *b)
182 template <
class Derived>
183 bool LessThanByMetaClass<Derived>::baseLess(
const void *,
const void *)
188 template <
class Derived>
189 bool LessThanByMetaClass<Derived>::baseLess(
const CEmpty *,
const CEmpty *)
194 template <
class Derived>
195 template <
typename T,
typename Flags>
196 bool LessThanByMetaClass<Derived>::membersLess(
bool &io_greaterThan,
const T &a,
const T &b, Flags)
198 if (io_greaterThan) {
return false; }
201 io_greaterThan = b.compare(a, Qt::CaseInsensitive) < 0;
202 return a.compare(b, Qt::CaseInsensitive) < 0;
206 io_greaterThan = b < a;
214 template <
class Derived>
219 friend int compare(
const Derived &a,
const Derived &b) {
return compareImpl(a, b); }
222 static int compareImpl(
const Derived &a,
const Derived &b);
223 template <
typename T>
224 static int baseCompare(
const T *a,
const T *b);
225 static int baseCompare(
const void *,
const void *);
227 template <
typename T,
typename Flags>
228 static int membersCompare(
const T &a,
const T &b, Flags);
231 template <
class Derived>
232 int CompareByMetaClass<Derived>::compareImpl(
const Derived &a,
const Derived &b)
236 introspect<Derived>().forEachMember([&](
auto member) {
239 result = result ? result :
240 CompareByMetaClass::membersCompare(member.in(a), member.in(b), member.m_flags);
246 template <
class Derived>
247 template <
typename T>
248 int CompareByMetaClass<Derived>::baseCompare(
const T *a,
const T *b)
253 template <
class Derived>
254 int CompareByMetaClass<Derived>::baseCompare(
const void *,
const void *)
259 template <
class Derived>
260 int CompareByMetaClass<Derived>::baseCompare(
const CEmpty *,
const CEmpty *)
265 template <
class Derived>
266 template <
typename T,
typename Flags>
267 int CompareByMetaClass<Derived>::membersCompare(
const T &a,
const T &b, Flags)
271 return a.compare(b, Qt::CaseInsensitive);
273 else if constexpr (THasCompare<T, T>::value) {
return compare(a, b); }
274 else {
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.
Free functions in swift::misc.
typename TBaseOf< T >::type TBaseOfT
Alias for typename TBaseOf<T>::type.