swift
Loading...
Searching...
No Matches
src
misc
comparefunctions.h
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6
#ifndef SWIFT_MISC_COMPAREFUNCTIONS_H
7
#define SWIFT_MISC_COMPAREFUNCTIONS_H
8
9
#include <type_traits>
10
11
#include <QDateTime>
12
#include <QFlags>
13
14
namespace
swift::misc::Compare
15
{
17
template
<
typename
T>
18
int
compare
(T a, T b)
requires
(std::is_arithmetic_v<T>)
19
{
20
if
(a < b)
21
{
22
return
-1;
23
}
24
if
(b < a)
25
{
26
return
1;
27
}
28
return
0;
29
}
30
32
template
<
typename
T>
33
int
compare
(T a, T b)
requires
(std::is_enum_v<T>)
34
{
35
using
UT = std::underlying_type_t<T>;
36
return
compare
(
static_cast<
UT
>
(a),
static_cast<
UT
>
(b));
37
}
38
40
template
<
typename
T>
41
int
compare
(
QFlags<T>
a,
QFlags<T>
b)
42
{
43
using
UT =
typename
QFlags<T>::Int
;
44
return
compare
(
static_cast<
UT
>
(a),
static_cast<
UT
>
(b));
45
}
46
48
inline
int
compare
(
const
QDateTime
&a,
const
QDateTime
&b)
49
{
50
return
compare
(a.
toMSecsSinceEpoch
(), b.
toMSecsSinceEpoch
());
51
}
52
}
// namespace swift::misc::Compare
53
54
#endif
// SWIFT_MISC_COMPAREFUNCTIONS_H
swift::misc::Compare::compare
int compare(T a, T b)
Compare arithmetic values.
Definition
comparefunctions.h:18
QDateTime
QDateTime::toMSecsSinceEpoch
qint64 toMSecsSinceEpoch() const const
QFlags
QFlags::Int
typedef Int
Generated on
for swift by
1.15.0