mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 21:45:34 +08:00
Use nested namespaces (C++17 feature)
This commit is contained in:
@@ -15,41 +15,38 @@
|
||||
#include <QDateTime>
|
||||
#include <type_traits>
|
||||
|
||||
namespace BlackMisc
|
||||
namespace BlackMisc::Compare
|
||||
{
|
||||
namespace Compare
|
||||
//! Compare arithmetic values
|
||||
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, int> = 0>
|
||||
int compare(T a, T b)
|
||||
{
|
||||
//! Compare arithmetic values
|
||||
template <typename T, std::enable_if_t<std::is_arithmetic_v<T>, int> = 0>
|
||||
int compare(T a, T b)
|
||||
{
|
||||
if (a < b) { return -1; }
|
||||
if (b < a) { return 1; }
|
||||
return 0;
|
||||
}
|
||||
if (a < b) { return -1; }
|
||||
if (b < a) { return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
//! Compare enumerators
|
||||
template <typename T, std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
int compare(T a, T b)
|
||||
{
|
||||
using UT = std::underlying_type_t<T>;
|
||||
return compare(static_cast<UT>(a), static_cast<UT>(b));
|
||||
}
|
||||
//! Compare enumerators
|
||||
template <typename T, std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
int compare(T a, T b)
|
||||
{
|
||||
using UT = std::underlying_type_t<T>;
|
||||
return compare(static_cast<UT>(a), static_cast<UT>(b));
|
||||
}
|
||||
|
||||
//! Compare QFlags
|
||||
template <typename T>
|
||||
int compare(QFlags<T> a, QFlags<T> b)
|
||||
{
|
||||
using UT = typename QFlags<T>::Int;
|
||||
return compare(static_cast<UT>(a), static_cast<UT>(b));
|
||||
}
|
||||
//! Compare QFlags
|
||||
template <typename T>
|
||||
int compare(QFlags<T> a, QFlags<T> b)
|
||||
{
|
||||
using UT = typename QFlags<T>::Int;
|
||||
return compare(static_cast<UT>(a), static_cast<UT>(b));
|
||||
}
|
||||
|
||||
//! Compare dates
|
||||
inline int compare(const QDateTime &a, const QDateTime &b)
|
||||
{
|
||||
return compare(a.toMSecsSinceEpoch(), b.toMSecsSinceEpoch());
|
||||
}
|
||||
} // ns
|
||||
//! Compare dates
|
||||
inline int compare(const QDateTime &a, const QDateTime &b)
|
||||
{
|
||||
return compare(a.toMSecsSinceEpoch(), b.toMSecsSinceEpoch());
|
||||
}
|
||||
} // ns
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user