diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-03-19 01:02:52 +0200 |
---|---|---|
committer | Ahmad Samir <a.samirh78@gmail.com> | 2023-03-21 05:35:22 +0200 |
commit | b46e0b0ab2a74384ad0cbe8deb08f62472eeb064 (patch) | |
tree | 5806f0bc0b00dc1332dfec35ea42fe7776df071b | |
parent | 092563a3d06026a0e64d2f0f1d926e6aa34955fd (diff) |
QLocaleData: replace two static helpers with if constexpr
More readable.
Change-Id: I015e5df2e67d8ca2b8eb117e2d63db8f9280a2a3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/text/qlocale.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index ca2d25438f..f8c98c4c16 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -1353,26 +1353,18 @@ QString QLocale::name() const return view + u'_' + d->territoryCode(); } -static qlonglong toIntegral_helper(const QLocaleData *d, QStringView str, bool *ok, - QLocale::NumberOptions mode, qlonglong) -{ - return d->stringToLongLong(str, 10, ok, mode); -} - -static qulonglong toIntegral_helper(const QLocaleData *d, QStringView str, bool *ok, - QLocale::NumberOptions mode, qulonglong) -{ - return d->stringToUnsLongLong(str, 10, ok, mode); -} - template <typename T> static inline T toIntegral_helper(const QLocalePrivate *d, QStringView str, bool *ok) { - using Int64 = - typename std::conditional<std::is_unsigned<T>::value, qulonglong, qlonglong>::type; + constexpr bool isUnsigned = std::is_unsigned_v<T>; + using Int64 = typename std::conditional_t<isUnsigned, quint64, qint64>; + + Int64 val = 0; + if constexpr (isUnsigned) + val = d->m_data->stringToUnsLongLong(str, 10, ok, d->m_numberOptions); + else + val = d->m_data->stringToLongLong(str, 10, ok, d->m_numberOptions); - // we select the right overload by the last, unused parameter - Int64 val = toIntegral_helper(d->m_data, str, ok, d->m_numberOptions, Int64()); if (T(val) != val) { if (ok != nullptr) *ok = false; |