From 6f0df02d002356625f10683ef84da7685d92a2c4 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 12 Aug 2020 14:14:02 +0200 Subject: Replace Qt CONSTEXPR defines with constexpr Both normal and relaxed constexpr are required by our new minimum of C++17. Change-Id: Ic028b88a2e7a6cb7d5925f3133b9d54859a81744 Reviewed-by: Sona Kurazyan --- src/corelib/text/qstringview.h | 56 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) (limited to 'src/corelib/text/qstringview.h') diff --git a/src/corelib/text/qstringview.h b/src/corelib/text/qstringview.h index 24cea33e7f..f2e9f876f9 100644 --- a/src/corelib/text/qstringview.h +++ b/src/corelib/text/qstringview.h @@ -170,13 +170,13 @@ private: } template - static Q_DECL_CONSTEXPR qsizetype lengthHelperContainer(const Container &c) noexcept + static constexpr qsizetype lengthHelperContainer(const Container &c) noexcept { return qsizetype(std::size(c)); } template - static Q_DECL_CONSTEXPR qsizetype lengthHelperContainer(const Char (&)[N]) noexcept + static constexpr qsizetype lengthHelperContainer(const Char (&)[N]) noexcept { return qsizetype(N - 1); } @@ -184,34 +184,34 @@ private: template static const storage_type *castHelper(const Char *str) noexcept { return reinterpret_cast(str); } - static Q_DECL_CONSTEXPR const storage_type *castHelper(const storage_type *str) noexcept + static constexpr const storage_type *castHelper(const storage_type *str) noexcept { return str; } public: - Q_DECL_CONSTEXPR QStringView() noexcept + constexpr QStringView() noexcept : m_size(0), m_data(nullptr) {} - Q_DECL_CONSTEXPR QStringView(std::nullptr_t) noexcept + constexpr QStringView(std::nullptr_t) noexcept : QStringView() {} template = true> - Q_DECL_CONSTEXPR QStringView(const Char *str, qsizetype len) + constexpr QStringView(const Char *str, qsizetype len) : m_size((Q_ASSERT(len >= 0), Q_ASSERT(str || !len), len)), m_data(castHelper(str)) {} template = true> - Q_DECL_CONSTEXPR QStringView(const Char *f, const Char *l) + constexpr QStringView(const Char *f, const Char *l) : QStringView(f, l - f) {} #ifdef Q_CLANG_QDOC template - Q_DECL_CONSTEXPR QStringView(const Char (&array)[N]) noexcept; + constexpr QStringView(const Char (&array)[N]) noexcept; template - Q_DECL_CONSTEXPR QStringView(const Char *str) noexcept; + constexpr QStringView(const Char *str) noexcept; #else template = true> - Q_DECL_CONSTEXPR QStringView(const Pointer &str) noexcept + constexpr QStringView(const Pointer &str) noexcept : QStringView(str, str ? lengthHelperPointer(str) : 0) {} #endif @@ -225,7 +225,7 @@ public: #endif template = true> - Q_DECL_CONSTEXPR QStringView(const Container &c) noexcept + constexpr QStringView(const Container &c) noexcept : QStringView(std::data(c), lengthHelperContainer(c)) {} Q_REQUIRED_RESULT inline QString toString() const; // defined in qstring.h @@ -235,12 +235,12 @@ public: Q_REQUIRED_RESULT Q_CORE_EXPORT NSString *toNSString() const Q_DECL_NS_RETURNS_AUTORELEASED; #endif - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR qsizetype size() const noexcept { return m_size; } + Q_REQUIRED_RESULT constexpr qsizetype size() const noexcept { return m_size; } Q_REQUIRED_RESULT const_pointer data() const noexcept { return reinterpret_cast(m_data); } Q_REQUIRED_RESULT const_pointer constData() const noexcept { return data(); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR const storage_type *utf16() const noexcept { return m_data; } + Q_REQUIRED_RESULT constexpr const storage_type *utf16() const noexcept { return m_data; } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar operator[](qsizetype n) const + Q_REQUIRED_RESULT constexpr QChar operator[](qsizetype n) const { return Q_ASSERT(n >= 0), Q_ASSERT(n < size()), QChar(m_data[n]); } // @@ -255,7 +255,7 @@ public: Q_REQUIRED_RESULT QByteArray toLocal8Bit() const { return QtPrivate::convertToLocal8Bit(*this); } Q_REQUIRED_RESULT inline QList toUcs4() const; // defined in qlist.h - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar at(qsizetype n) const { return (*this)[n]; } + Q_REQUIRED_RESULT constexpr QChar at(qsizetype n) const { return (*this)[n]; } Q_REQUIRED_RESULT constexpr QStringView mid(qsizetype pos, qsizetype n = -1) const { @@ -284,12 +284,12 @@ public: { Q_ASSERT(pos >= 0); Q_ASSERT(pos <= size()); return QStringView(m_data + pos, size() - pos); } Q_REQUIRED_RESULT constexpr QStringView sliced(qsizetype pos, qsizetype n) const { Q_ASSERT(pos >= 0); Q_ASSERT(n >= 0); Q_ASSERT(size_t(pos) + size_t(n) <= size_t(size())); return QStringView(m_data + pos, n); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QStringView chopped(qsizetype n) const + Q_REQUIRED_RESULT constexpr QStringView chopped(qsizetype n) const { return Q_ASSERT(n >= 0), Q_ASSERT(n <= size()), QStringView(m_data, m_size - n); } - Q_DECL_RELAXED_CONSTEXPR void truncate(qsizetype n) + constexpr void truncate(qsizetype n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size = n; } - Q_DECL_RELAXED_CONSTEXPR void chop(qsizetype n) + constexpr void chop(qsizetype n) { Q_ASSERT(n >= 0); Q_ASSERT(n <= size()); m_size -= n; } Q_REQUIRED_RESULT QStringView trimmed() const noexcept { return QtPrivate::trimmed(*this); } @@ -303,7 +303,7 @@ public: Q_REQUIRED_RESULT int compare(QStringView other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept { return QtPrivate::compareStrings(*this, other, cs); } Q_REQUIRED_RESULT inline int compare(QLatin1String other, Qt::CaseSensitivity cs = Qt::CaseSensitive) const noexcept; - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR int compare(QChar c) const noexcept + Q_REQUIRED_RESULT constexpr int compare(QChar c) const noexcept { return size() >= 1 ? compare_single_char_helper(*utf16() - c.unicode()) : -1; } Q_REQUIRED_RESULT int compare(QChar c, Qt::CaseSensitivity cs) const noexcept { return QtPrivate::compareStrings(*this, QStringView(&c, 1), cs); } @@ -392,24 +392,24 @@ public: Q_REQUIRED_RESULT const_reverse_iterator crbegin() const noexcept { return rbegin(); } Q_REQUIRED_RESULT const_reverse_iterator crend() const noexcept { return rend(); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool empty() const noexcept { return size() == 0; } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); } + Q_REQUIRED_RESULT constexpr bool empty() const noexcept { return size() == 0; } + Q_REQUIRED_RESULT constexpr QChar front() const { return Q_ASSERT(!empty()), QChar(m_data[0]); } + Q_REQUIRED_RESULT constexpr QChar back() const { return Q_ASSERT(!empty()), QChar(m_data[m_size - 1]); } // // Qt compatibility API: // - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool isNull() const noexcept { return !m_data; } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR bool isEmpty() const noexcept { return empty(); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR int length() const /* not nothrow! */ + Q_REQUIRED_RESULT constexpr bool isNull() const noexcept { return !m_data; } + Q_REQUIRED_RESULT constexpr bool isEmpty() const noexcept { return empty(); } + Q_REQUIRED_RESULT constexpr int length() const /* not nothrow! */ { return Q_ASSERT(int(size()) == size()), int(size()); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar first() const { return front(); } - Q_REQUIRED_RESULT Q_DECL_CONSTEXPR QChar last() const { return back(); } + Q_REQUIRED_RESULT constexpr QChar first() const { return front(); } + Q_REQUIRED_RESULT constexpr QChar last() const { return back(); } private: qsizetype m_size; const storage_type *m_data; - Q_DECL_CONSTEXPR int compare_single_char_helper(int diff) const noexcept + constexpr int compare_single_char_helper(int diff) const noexcept { return diff ? diff : size() > 1 ? 1 : 0; } }; Q_DECLARE_TYPEINFO(QStringView, Q_PRIMITIVE_TYPE); -- cgit v1.2.3