From db4e408ca9dab18c6f80c9e0522b19bc80a924b9 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Tue, 3 Dec 2024 14:06:17 +0100 Subject: [PATCH] QMap/QHash: mark isEmpty() / empty() as [[nodiscard]] Cone of shame, they should've been marked as such since day 1. Change-Id: I9aaf6567e183e4ece5443f4fbf12eb3a251501d5 Pick-to: 6.5 Reviewed-by: Thiago Macieira (cherry picked from commit 091bb2f997c2bbe4e44d66527f13c435288e0562) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/tools/qhash.h | 5 +++++ src/corelib/tools/qmap.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 8446e82624a..62f7e9be640 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -929,6 +929,8 @@ public: #endif // Q_QDOC inline qsizetype size() const noexcept { return d ? qsizetype(d->size) : 0; } + + [[nodiscard]] inline bool isEmpty() const noexcept { return !d || d->size == 0; } inline qsizetype capacity() const noexcept { return d ? qsizetype(d->numBuckets >> 1) : 0; } @@ -1363,6 +1365,7 @@ public: size_t bucket_count() const noexcept { return d ? d->numBuckets : 0; } static size_t max_bucket_count() noexcept { return Data::maxNumBuckets(); } + [[nodiscard]] inline bool empty() const noexcept { return isEmpty(); } private: @@ -1609,6 +1612,7 @@ public: inline qsizetype size() const noexcept { return m_size; } + [[nodiscard]] inline bool isEmpty() const noexcept { return !m_size; } inline qsizetype capacity() const noexcept { return d ? qsizetype(d->numBuckets >> 1) : 0; } @@ -2118,6 +2122,7 @@ public: size_t bucket_count() const noexcept { return d ? d->numBuckets : 0; } static size_t max_bucket_count() noexcept { return Data::maxNumBuckets(); } + [[nodiscard]] inline bool empty() const noexcept { return isEmpty(); } inline iterator replace(const Key &key, const T &value) diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index 326ae7d8a51..0fd025e2b70 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -267,6 +267,7 @@ public: size_type size() const { return d ? size_type(d->m.size()) : size_type(0); } + [[nodiscard]] bool isEmpty() const { return d ? d->m.empty() : true; } void detach() @@ -759,6 +760,7 @@ public: } // STL compatibility + [[nodiscard]] inline bool empty() const { return isEmpty(); @@ -938,6 +940,7 @@ public: size_type size() const { return d ? size_type(d->m.size()) : size_type(0); } + [[nodiscard]] bool isEmpty() const { return d ? d->m.empty() : true; } void detach() @@ -1518,6 +1521,7 @@ public: } // STL compatibility + [[nodiscard]] inline bool empty() const { return isEmpty(); } std::pair equal_range(const Key &akey)