Use nested namespaces (C++17 feature)

This commit is contained in:
Mat Sutcliffe
2021-09-15 21:44:54 +01:00
parent 3f2e5b0b69
commit 57d32da826
1345 changed files with 146075 additions and 150376 deletions

View File

@@ -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