diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-24 12:19:45 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-25 08:18:03 +0200 |
commit | d3643d9690d82733ae25000c789a113389d4f874 (patch) | |
tree | 540d1e20f87b3587fe87d8b909f02a2f3480bd32 /src/corelib/text/qstringview.h | |
parent | 01697c5f9bc589537184cfe01972cd75b2965a72 (diff) |
Use c++20 when available at compile time
Also std::end is constexpr where std::next sometimes isn't always with
sanitizers active.
Change-Id: Ibe4c11eb4945fb286247e841b6a7f6cc3ff1eaa6
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/corelib/text/qstringview.h')
-rw-r--r-- | src/corelib/text/qstringview.h | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 86ffb3cc9e..d29e6be4f8 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -150,13 +150,12 @@ private: template <typename Char> static qsizetype lengthHelperPointer(const Char *str) noexcept { -#if defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) - if (__builtin_constant_p(*str)) { - qsizetype result = 0; - while (*str++) - ++result; - return result; - } +#if defined(__cpp_lib_is_constant_evaluated) + if (std::is_constant_evaluated()) + return std::char_traits<Char>::length(str); +#elif defined(Q_CC_GNU) && !defined(Q_CC_CLANG) && !defined(Q_CC_INTEL) + if (__builtin_constant_p(*str)) + return std::char_traits<Char>::length(str); #endif return QtPrivate::qustrlen(reinterpret_cast<const char16_t *>(str)); } @@ -175,7 +174,7 @@ private: static constexpr qsizetype lengthHelperContainer(const Char (&str)[N]) noexcept { const auto it = std::char_traits<Char>::find(str, N, Char(0)); - const auto end = it ? it : std::next(str, N); + const auto end = it ? it : std::end(str); return qsizetype(std::distance(str, end)); } |