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 <thiago.macieira@intel.com>
(cherry picked from commit 091bb2f997c2bbe4e44d66527f13c435288e0562)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Giuseppe D'Angelo 2024-12-03 14:06:17 +01:00 committed by Qt Cherry-pick Bot
parent 3210c4c691
commit db4e408ca9
2 changed files with 9 additions and 0 deletions

View File

@ -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)

View File

@ -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<iterator, iterator> equal_range(const Key &akey)