diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 8446e82624..62f7e9be64 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 326ae7d8a5..0fd025e2b7 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)