From b46e0b0ab2a74384ad0cbe8deb08f62472eeb064 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Sun, 19 Mar 2023 01:02:52 +0200 Subject: [PATCH] QLocaleData: replace two static helpers with if constexpr More readable. Change-Id: I015e5df2e67d8ca2b8eb117e2d63db8f9280a2a3 Reviewed-by: Thiago Macieira --- src/corelib/text/qlocale.cpp | 24 ++++++++---------------- 1 file 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 static inline T toIntegral_helper(const QLocalePrivate *d, QStringView str, bool *ok) { - using Int64 = - typename std::conditional::value, qulonglong, qlonglong>::type; + constexpr bool isUnsigned = std::is_unsigned_v; + using Int64 = typename std::conditional_t; + + 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;