Skip to content

Commit

Permalink
QSet: add missing insert-with-hint
Browse files Browse the repository at this point in the history
Since QHash is missing the overload, too, just ignore the hint for
now, but provide the STL-compatible signature so generic code can use
QSet as a normal sequential container.

[ChangeLog][QtCore][QSet] Added insert() overload taking an insertion
hint, for STL compatibility.

Change-Id: I9fe41877343ebff721b650fb7b9cd4e06b6608d8
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Andrei Golubev <[email protected]>
  • Loading branch information
marc-kdab authored and dangelog committed Nov 25, 2020
1 parent 61436f2 commit 3f8896d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/corelib/tools/qset.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ class QSet
typedef qsizetype size_type;

inline bool empty() const { return isEmpty(); }

iterator insert(const_iterator, const T &value) { return insert(value); }

// comfort
inline QSet<T> &operator<<(const T &value) { insert(value); return *this; }
inline QSet<T> &operator|=(const QSet<T> &other) { unite(other); return *this; }
Expand Down
16 changes: 16 additions & 0 deletions src/corelib/tools/qset.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@
for STL compatibility. It is equivalent to isEmpty().
*/

/*!
\fn QSet::insert(const_iterator it, const T &value)
\overload
\since 6.1

Inserts item \a value into the set, if \a value isn't already
in the set, and returns an iterator pointing at the inserted
item.

The iterator \a it is ignored.

This function is provided for compatibility with the STL.

\sa operator<<(), remove(), contains()
*/

/*!
\fn template <class T> bool QSet<T>::count() const

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static_assert(!QContainerInfo::can_set_value_at_iterator_v<std::set<int>>);
static_assert(QContainerInfo::can_set_value_at_iterator_v<std::forward_list<int>>);

static_assert(QContainerInfo::can_insert_value_at_iterator_v<QVector<int>>);
static_assert(!QContainerInfo::can_insert_value_at_iterator_v<QSet<int>>);
static_assert(QContainerInfo::can_insert_value_at_iterator_v<QSet<int>>);
static_assert(!QContainerInfo::can_insert_value_at_iterator_v<NotAContainer>);
static_assert(QContainerInfo::can_insert_value_at_iterator_v<std::vector<int>>);
static_assert(!QContainerInfo::can_insert_value_at_iterator_v<std::forward_list<int>>);
Expand Down Expand Up @@ -267,7 +267,7 @@ void tst_QMetaContainer::testSequence_data()
<< static_cast<void *>(&qset)
<< QMetaSequence::fromContainer<QSet<QByteArray>>()
<< QMetaType::fromType<QByteArray>()
<< true << false << false << false << false << false << true << false;
<< true << false << false << false << false << true << true << false;
QTest::addRow("std::set")
<< static_cast<void *>(&stdset)
<< QMetaSequence::fromContainer<std::set<int>>()
Expand Down

0 comments on commit 3f8896d

Please sign in to comment.