Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qset.qdoc
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \class QSet
6 \inmodule QtCore
7 \brief The QSet class is a template class that provides a hash-table-based set.
8 \compares equality
9
10 \ingroup tools
11 \ingroup shared
12 \reentrant
13
14
15 QSet<T> is one of Qt's generic \l{container classes}, where \a T
16 specifies the type of values stored in the set. It stores values in
17 an unspecified order and provides very fast lookup of the values.
18 Internally, QSet<T> is implemented as a QHash.
19
20 Here's an example QSet with QString values:
21
22 \snippet code/doc_src_qset.cpp 0
23
24 To insert a value into the set, use insert():
25
26 \snippet code/doc_src_qset.cpp 1
27
28 Another way to insert items into the set is to use \l operator<<():
29
30 \snippet code/doc_src_qset.cpp 2
31
32 To test whether an item belongs to the set or not, use contains():
33
34 \snippet code/doc_src_qset.cpp 3
35
36 If you want to navigate through all the values stored in a QSet,
37 you can use an iterator. QSet supports both \l{Java-style
38 iterators} (QSetIterator and QMutableSetIterator) and \l{STL-style
39 iterators} (QSet::iterator and QSet::const_iterator). Here's how
40 to iterate over a QSet<QWidget *> using a Java-style iterator:
41
42 \snippet code/doc_src_qset.cpp 4
43
44 Here's the same code, but using an STL-style iterator:
45
46 \snippet code/doc_src_qset.cpp 5
47
48 QSet is unordered, so an iterator's sequence cannot be assumed to
49 be predictable. If ordering by key is required, use a QMap.
50
51 To navigate through a QSet, you can also use range-based for:
52
53 \snippet code/doc_src_qset.cpp 6
54
55 Items can be removed from the set using remove(). There is also a
56 clear() function that removes all items.
57
58 QSet's value data type must be an \l{assignable data type}. You
59 cannot, for example, store a QWidget as a value; instead, store a
60 QWidget *. In addition, the type must provide \c operator==(), and
61 there must also be a global qHash() function that returns a hash
62 value for an argument of the key's type. See the QHash
63 documentation for a list of types supported by qHash().
64
65 Internally, QSet uses a hash table to perform lookups. The hash
66 table automatically grows and shrinks to provide fast lookups
67 without wasting memory. You can still control the size of the hash
68 table by calling reserve(), if you already know approximately how
69 many elements the QSet will contain, but this isn't necessary to
70 obtain good performance. You can also call capacity() to retrieve
71 the hash table's size.
72
73 \sa QSetIterator, QMutableSetIterator, QHash, QMap
74*/
75
76/*!
77 \fn template <class T> QSet<T>::QSet()
78
79 Constructs an empty set.
80
81 \sa clear()
82*/
83
84/*! \fn template <class T> QSet<T>::QSet(std::initializer_list<T> list)
85 \since 5.1
86
87 Constructs a set with a copy of each of the elements in the
88 initializer list \a list.
89*/
90
91/*! \fn template <class T> template <typename InputIterator, QtPrivate::IfIsInputIterator<InputIterator> = true> QSet<T>::QSet(InputIterator first, InputIterator last)
92 \since 5.14
93
94 Constructs a set with the contents in the iterator range [\a first, \a last).
95
96 The value type of \c InputIterator must be convertible to \c T.
97
98 \note If the range [\a first, \a last) contains duplicate elements,
99 the first one is retained.
100*/
101
102/*!
103 \fn template <class T> void QSet<T>::swap(QSet<T> &other)
104 \memberswap{set}
105*/
106
107/*!
108 \fn template <class T> bool QSet<T>::operator==(const QSet<T> &lhs, const QSet<T> &rhs)
109
110 Returns \c true if the \a lhs set is equal to the \a rhs set; otherwise
111 returns \c false.
112
113 Two sets are considered equal if they contain the same elements.
114
115 This function requires the value type to implement \c operator==().
116
117 \sa operator!=()
118*/
119
120/*!
121 \fn template <class T> bool QSet<T>::operator!=(const QSet<T> &lhs, const QSet<T> &rhs)
122
123 Returns \c true if the \a lhs set is not equal to the \a rhs set; otherwise
124 returns \c false.
125
126 Two sets are considered equal if they contain the same elements.
127
128 This function requires the value type to implement \c operator==().
129
130 \sa operator==()
131*/
132
133/*!
134 \fn template <class T> int QSet<T>::size() const
135
136 Returns the number of items in the set.
137
138 \sa isEmpty(), count()
139*/
140
141/*!
142 \fn template <class T> bool QSet<T>::isEmpty() const
143
144 Returns \c true if the set contains no elements; otherwise returns
145 false.
146
147 \sa size()
148*/
149
150/*!
151 \fn template <class T> int QSet<T>::capacity() const
152
153 Returns the number of buckets in the set's internal hash
154 table.
155
156 The sole purpose of this function is to provide a means of fine
157 tuning QSet's memory usage. In general, you will rarely ever need
158 to call this function. If you want to know how many items are in
159 the set, call size().
160
161 \sa reserve(), squeeze()
162*/
163
164/*! \fn template <class T> void QSet<T>::reserve(qsizetype size)
165
166 Ensures that the set's internal hash table consists of at
167 least \a size buckets.
168
169 This function is useful for code that needs to build a huge set
170 and wants to avoid repeated reallocation. For example:
171
172 \snippet code/doc_src_qset.cpp 7
173
174 Ideally, \a size should be slightly more than the maximum number
175 of elements expected in the set. \a size doesn't have to be prime,
176 because QSet will use a prime number internally anyway. If \a size
177 is an underestimate, the worst that will happen is that the QSet
178 will be a bit slower.
179
180 In general, you will rarely ever need to call this function.
181 QSet's internal hash table automatically shrinks or grows to
182 provide good performance without wasting too much memory.
183
184 \sa squeeze(), capacity()
185*/
186
187/*!
188 \fn template <class T> void QSet<T>::squeeze()
189
190 Reduces the size of the set's internal hash table to save
191 memory.
192
193 The sole purpose of this function is to provide a means of fine
194 tuning QSet's memory usage. In general, you will rarely ever
195 need to call this function.
196
197 \sa reserve(), capacity()
198*/
199
200/*!
201 \fn template <class T> void QSet<T>::detach()
202
203 \internal
204
205 Detaches this set from any other sets with which it may share
206 data.
207
208 \sa isDetached()
209*/
210
211/*! \fn template <class T> bool QSet<T>::isDetached() const
212
213 \internal
214
215 Returns \c true if the set's internal data isn't shared with any
216 other set object; otherwise returns \c false.
217
218 \sa detach()
219*/
220
221/*!
222 \fn template <class T> void QSet<T>::setSharable(bool sharable)
223 \internal
224*/
225
226/*!
227 \fn template <class T> void QSet<T>::clear()
228
229 Removes all elements from the set.
230
231 \sa remove()
232*/
233
234/*!
235 \fn template <class T> bool QSet<T>::remove(const T &value)
236
237 Removes any occurrence of item \a value from the set. Returns
238 true if an item was actually removed; otherwise returns \c false.
239
240 \sa contains(), insert()
241*/
242
243/*!
244 \fn template <class T> QSet<T>::iterator QSet<T>::erase(const_iterator pos)
245 \since 5.7
246
247 Removes the item at the iterator position \a pos from the set, and
248 returns an iterator positioned at the next item in the set.
249
250 Unlike remove(), this function never causes QSet to rehash its
251 internal data structure. This means that it can safely be called
252 while iterating, and won't affect the order of items in the set.
253
254 \note The iterator \a pos \e must be valid and dereferenceable. Calling this
255 method on any other iterator, including its own \l end(), results in
256 undefined behavior. In particular, even the \l begin() iterator of an empty
257 set cannot be dereferenced.
258
259 \sa remove(), find()
260*/
261
262/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::find(const T &value) const
263 \since 4.2
264
265 Returns a const iterator positioned at the item \a value in the
266 set. If the set contains no item \a value, the function returns
267 constEnd().
268
269 \sa constFind(), contains()
270*/
271
272/*! \fn template <class T> QSet<T>::iterator QSet<T>::find(const T &value)
273 \since 4.2
274 \overload
275
276 Returns a non-const iterator positioned at the item \a value in
277 the set. If the set contains no item \a value, the function
278 returns end().
279*/
280
281/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::constFind(const T &value) const
282 \since 4.2
283
284 Returns a const iterator positioned at the item \a value in the
285 set. If the set contains no item \a value, the function returns
286 constEnd().
287
288 \sa find(), contains()
289*/
290
291/*!
292 \fn template <class T> bool QSet<T>::contains(const T &value) const
293
294 Returns \c true if the set contains item \a value; otherwise returns
295 false.
296
297 \sa insert(), remove(), find()
298*/
299
300/*!
301 \fn template <class T> bool QSet<T>::contains(const QSet<T> &other) const
302 \since 4.6
303
304 Returns \c true if the set contains all items from the \a other set;
305 otherwise returns \c false.
306
307 \sa insert(), remove(), find()
308*/
309
310/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::begin() const
311
312 Returns a const \l{STL-style iterators}{STL-style iterator} positioned at the first
313 item in the set.
314
315 \sa constBegin(), end()
316*/
317
318/*! \fn template <class T> QSet<T>::iterator QSet<T>::begin()
319 \since 4.2
320 \overload
321
322 Returns a non-const \l{STL-style iterators}{STL-style iterator} positioned at the first
323 item in the set.
324*/
325
326/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::cbegin() const
327 \since 5.0
328
329 Returns a const \l{STL-style iterators}{STL-style iterator} positioned at the first
330 item in the set.
331
332 \sa begin(), cend()
333*/
334
335/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::constBegin() const
336
337 Returns a const \l{STL-style iterators}{STL-style iterator} positioned at the first
338 item in the set.
339
340 \sa begin(), constEnd()
341*/
342
343/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::end() const
344
345 Returns a const \l{STL-style iterators}{STL-style iterator} positioned at the imaginary
346 item after the last item in the set.
347
348 \sa constEnd(), begin()
349*/
350
351/*! \fn template <class T> QSet<T>::iterator QSet<T>::end()
352 \since 4.2
353 \overload
354
355 Returns a non-const \l{STL-style iterators}{STL-style iterator} pointing to the
356 imaginary item after the last item in the set.
357*/
358
359/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::cend() const
360 \since 5.0
361
362 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
363 item after the last item in the set.
364
365 \sa cbegin(), end()
366*/
367
368/*! \fn template <class T> QSet<T>::const_iterator QSet<T>::constEnd() const
369
370 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
371 item after the last item in the set.
372
373 \sa constBegin(), end()
374*/
375
376/*!
377 \typedef QSet::Iterator
378 \since 4.2
379
380 Qt-style synonym for QSet::iterator.
381*/
382
383/*!
384 \typedef QSet::ConstIterator
385
386 Qt-style synonym for QSet::const_iterator.
387*/
388
389/*!
390 \typedef QSet::const_pointer
391
392 Typedef for const T *. Provided for STL compatibility.
393*/
394
395/*!
396 \typedef QSet::const_reference
397
398 Typedef for const T &. Provided for STL compatibility.
399*/
400
401/*!
402 \typedef QSet::difference_type
403
404 Typedef for const ptrdiff_t. Provided for STL compatibility.
405*/
406
407/*!
408 \typedef QSet::key_type
409
410 Typedef for T. Provided for STL compatibility.
411*/
412
413/*!
414 \typedef QSet::pointer
415
416 Typedef for T *. Provided for STL compatibility.
417*/
418
419/*!
420 \typedef QSet::reference
421
422 Typedef for T &. Provided for STL compatibility.
423*/
424
425/*!
426 \typedef QSet::size_type
427
428 Typedef for int. Provided for STL compatibility.
429*/
430
431/*!
432 \typedef QSet::value_type
433
434 Typedef for T. Provided for STL compatibility.
435*/
436
437/*!
438 \fn template <class T> QSet<T>::iterator QSet<T>::insert(const T &value)
439
440 Inserts item \a value into the set, if \a value isn't already
441 in the set, and returns an iterator pointing at the inserted
442 item.
443
444 \sa operator<<(), remove(), contains()
445*/
446
447/*!
448 \fn template <class T> QSet<T> &QSet<T>::unite(const QSet<T> &other)
449 \fn template <class T> QSet<T> &QSet<T>::unite(QSet &&other)
450
451 Each item in the \a other set that isn't already in this set is
452 inserted into this set. A reference to this set is returned.
453
454 \sa operator|=(), intersect(), subtract()
455*/
456
457/*!
458 \fn template <class T> QSet<T> &QSet<T>::intersect(const QSet<T> &other)
459
460 Removes all items from this set that are not contained in the
461 \a other set. A reference to this set is returned.
462
463 \sa intersects(), operator&=(), unite(), subtract()
464*/
465
466/*!
467 \fn template <class T> bool QSet<T>::intersects(const QSet<T> &other) const
468 \since 5.6
469
470 Returns \c true if this set has at least one item in common with
471 \a other.
472
473 \sa contains(), intersect()
474*/
475
476/*!
477 \fn template <class T> QSet<T> &QSet<T>::subtract(const QSet<T> &other)
478
479 Removes all items from this set that are contained in the
480 \a other set. Returns a reference to this set.
481
482 \sa operator-=(), unite(), intersect()
483*/
484
485/*!
486 \fn template <class T> bool QSet<T>::empty() const
487
488 Returns \c true if the set is empty. This function is provided
489 for STL compatibility. It is equivalent to isEmpty().
490*/
491
492/*!
493 \fn template <class T> QSet<T>::iterator QSet<T>::insert(const_iterator it, const T &value)
494 \overload
495 \since 6.1
496
497 Inserts item \a value into the set, if \a value isn't already
498 in the set, and returns an iterator pointing at the inserted
499 item.
500
501 The iterator \a it is ignored.
502
503 This function is provided for compatibility with the STL.
504
505 \sa operator<<(), remove(), contains()
506*/
507
508/*!
509 \fn template <class T> bool QSet<T>::count() const
510
511 Same as size().
512*/
513
514/*!
515 \fn template <class T> QSet<T> &QSet<T>::operator<<(const T &value)
516 \fn template <class T> QSet<T> &QSet<T>::operator+=(const T &value)
517 \fn template <class T> QSet<T> &QSet<T>::operator|=(const T &value)
518
519 Inserts a new item \a value and returns a reference to the set.
520 If \a value already exists in the set, the set is left unchanged.
521
522 \sa insert()
523*/
524
525/*!
526 \fn template <class T> QSet<T> &QSet<T>::operator-=(const T &value)
527
528 Removes the occurrence of item \a value from the set, if
529 it is found, and returns a reference to the set. If the
530 \a value is not contained the set, nothing is removed.
531
532 \sa remove()
533*/
534
535/*!
536 \fn template <class T> QSet<T> &QSet<T>::operator|=(const QSet<T> &other)
537 \fn template <class T> QSet<T> &QSet<T>::operator|=(QSet &&other)
538 \fn template <class T> QSet<T> &QSet<T>::operator+=(const QSet<T> &other)
539 \fn template <class T> QSet<T> &QSet<T>::operator+=(QSet &&other)
540
541 Same as \l {unite()} {unite(\a other)}.
542
543 \sa operator|(), operator&=(), operator-=()
544*/
545
546/*!
547 \fn template <class T> QSet<T> &QSet<T>::operator&=(const QSet<T> &other)
548
549 Same as \l {intersect()} {intersect(\a other)}.
550
551 \sa operator&(), operator|=(), operator-=()
552*/
553
554/*!
555 \fn template <class T> QSet<T> &QSet<T>::operator&=(const T &value)
556
557 \overload
558
559 Same as \l {intersect()} {intersect(\e{other})}, if we consider \e other to be a set
560 that contains the singleton \a value.
561*/
562
563
564/*!
565 \fn template <class T> QSet<T> &QSet<T>::operator-=(const QSet<T> &other)
566
567 Same as \l {subtract()} {subtract(\a{other})}.
568
569 \sa operator-(), operator|=(), operator&=()
570*/
571
572/*!
573 \fn template <class T> QSet<T> QSet<T>::operator|(const QSet &lhs, const QSet &rhs)
574 \fn template <class T> QSet<T> QSet<T>::operator|(const QSet &lhs, QSet &&rhs)
575 \fn template <class T> QSet<T> QSet<T>::operator|(QSet &&lhs, const QSet &rhs)
576 \fn template <class T> QSet<T> QSet<T>::operator|(QSet &&lhs, QSet &&rhs)
577 \fn template <class T> QSet<T> QSet<T>::operator+(const QSet &lhs, const QSet &rhs)
578 \fn template <class T> QSet<T> QSet<T>::operator+(const QSet &lhs, QSet &&rhs)
579 \fn template <class T> QSet<T> QSet<T>::operator+(QSet &&lhs, const QSet &rhs)
580 \fn template <class T> QSet<T> QSet<T>::operator+(QSet &&lhs, QSet &&rhs)
581
582 Returns a new QSet that is the union of sets \a lhs and \a rhs.
583
584 \sa unite(), operator|=(), operator&(), operator-()
585*/
586
587/*!
588 \fn template <class T> QSet<T> QSet<T>::operator&(const QSet &lhs, const QSet &rhs)
589 \fn template <class T> QSet<T> QSet<T>::operator&(QSet &&lhs, const QSet &rhs)
590
591 Returns a new QSet that is the intersection of sets \a lhs and \a rhs.
592
593 \sa intersect(), operator&=(), operator|(), operator-()
594*/
595
596/*!
597 \fn template <class T> QSet<T> QSet<T>::operator-(const QSet &lhs, const QSet &rhs)
598 \fn template <class T> QSet<T> QSet<T>::operator-(QSet &&lhs, const QSet &rhs)
599
600 Returns a new QSet that is the set difference of sets \a lhs and \a rhs.
601
602 \sa subtract(), operator-=(), operator|(), operator&()
603*/
604
605/*!
606 \class QSet::iterator
607 \inmodule QtCore
608 \since 4.2
609 \brief The QSet::iterator class provides an STL-style non-const iterator for QSet.
610
611 QSet features both \l{STL-style iterators} and
612 \l{Java-style iterators}. The STL-style iterators are more
613 low-level and more cumbersome to use; on the other hand, they are
614 slightly faster and, for developers who already know STL, have
615 the advantage of familiarity.
616
617 QSet<T>::iterator allows you to iterate over a QSet and to remove
618 items (using QSet::erase()) while you iterate. (QSet doesn't let
619 you \e modify a value through an iterator, because that
620 would potentially require moving the value in the internal hash
621 table used by QSet.) If you want to iterate over a const QSet,
622 you should use QSet::const_iterator. It is generally good
623 practice to use QSet::const_iterator on a non-const QSet as well,
624 unless you need to change the QSet through the iterator. Const
625 iterators are slightly faster, and can improve code readability.
626
627 The default QSet::iterator constructor creates an uninitialized
628 iterator. You must initialize it using a function like
629 QSet::begin(), QSet::end(), or QSet::insert() before you can
630 start iterating. Here's a typical loop that prints all the items
631 stored in a set:
632
633 \snippet code/doc_src_qset.cpp 8
634
635 Here's a loop that removes certain items (all those that start
636 with 'J') from a set while iterating:
637
638 \snippet code/doc_src_qset.cpp 9
639
640 STL-style iterators can be used as arguments to \l{generic
641 algorithms}. For example, here's how to find an item in the set
642 using the qFind() algorithm:
643
644 \snippet code/doc_src_qset.cpp 10
645
646 Multiple iterators can be used on the same set.
647
648 \warning Iterators on implicitly shared containers do not work
649 exactly like STL-iterators. You should avoid copying a container
650 while iterators are active on that container. For more information,
651 read \l{Implicit sharing iterator problem}.
652
653 \sa QSet::const_iterator, QMutableSetIterator
654*/
655
656/*!
657 \class QSet::const_iterator
658 \inmodule QtCore
659 \brief The QSet::const_iterator class provides an STL-style const iterator for QSet.
660 \since 4.2
661
662 QSet features both \l{STL-style iterators} and
663 \l{Java-style iterators}. The STL-style iterators are more
664 low-level and more cumbersome to use; on the other hand, they are
665 slightly faster and, for developers who already know STL, have
666 the advantage of familiarity.
667
668 QSet<Key, T>::const_iterator allows you to iterate over a QSet.
669 If you want to modify the QSet as you iterate over it, you must
670 use QSet::iterator instead. It is generally good practice to use
671 QSet::const_iterator on a non-const QSet as well, unless you need
672 to change the QSet through the iterator. Const iterators are
673 slightly faster, and can improve code readability.
674
675 The default QSet::const_iterator constructor creates an
676 uninitialized iterator. You must initialize it using a function
677 like QSet::begin(), QSet::end(), or QSet::insert() before you can
678 start iterating. Here's a typical loop that prints all the items
679 stored in a set:
680
681 \snippet code/doc_src_qset.cpp 11
682
683 STL-style iterators can be used as arguments to \l{generic
684 algorithms}. For example, here's how to find an item in the set
685 using the qFind() algorithm:
686
687 \snippet code/doc_src_qset.cpp 12
688
689 \warning Iterators on implicitly shared containers do not work
690 exactly like STL-iterators. You should avoid copying a container
691 while iterators are active on that container. For more information,
692 read \l{Implicit sharing iterator problem}.
693
694 \sa QSet::iterator, QSetIterator
695*/
696
697/*!
698 \fn template <class T> QSet<T>::iterator::iterator()
699 \fn template <class T> QSet<T>::const_iterator::const_iterator()
700
701 Constructs an uninitialized iterator.
702
703 Functions like operator*() and operator++() should not be called
704 on an uninitialized iterator. Use operator=() to assign a value
705 to it before using it.
706
707 \sa QSet::begin(), QSet::end()
708*/
709
710/*!
711 \fn template <class T> QSet<T>::iterator::iterator(typename Hash::iterator i)
712 \fn template <class T> QSet<T>::const_iterator::const_iterator(typename Hash::const_iterator i)
713
714 \internal
715*/
716
717/*!
718 \typedef QSet::iterator::iterator_category
719 \typedef QSet::const_iterator::iterator_category
720
721 Synonyms for \e {std::bidirectional_iterator_tag} indicating
722 these iterators are bidirectional iterators.
723 */
724
725/*!
726 \typedef QSet::iterator::difference_type
727 \typedef QSet::const_iterator::difference_type
728
729 \internal
730*/
731
732/*!
733 \typedef QSet::iterator::value_type
734 \typedef QSet::const_iterator::value_type
735
736 \internal
737*/
738
739/*!
740 \typedef QSet::iterator::pointer
741 \typedef QSet::const_iterator::pointer
742
743 \internal
744*/
745
746/*!
747 \typedef QSet::iterator::reference
748 \typedef QSet::const_iterator::reference
749
750 \internal
751*/
752
753/*!
754 \fn template <class T> QSet<T>::iterator::iterator(const iterator &other)
755 \fn template <class T> QSet<T>::const_iterator::const_iterator(const const_iterator &other)
756
757 Constructs a copy of \a other.
758*/
759
760/*!
761 \fn template <class T> QSet<T>::const_iterator::const_iterator(const iterator &other)
762 \since 4.2
763 \overload
764
765 Constructs a copy of \a other.
766*/
767
768/*!
769 \fn template <class T> QSet<T>::iterator &QSet<T>::iterator::operator=(const iterator &other)
770 \fn template <class T> QSet<T>::const_iterator &QSet<T>::const_iterator::operator=(const const_iterator &other)
771
772 Assigns \a other to this iterator.
773*/
774
775/*!
776 \fn template <class T> const T &QSet<T>::iterator::operator*() const
777 \fn template <class T> const T &QSet<T>::const_iterator::operator*() const
778
779 Returns a reference to the current item.
780
781 \sa operator->()
782*/
783
784/*!
785 \fn template <class T> const T *QSet<T>::iterator::operator->() const
786 \fn template <class T> const T *QSet<T>::const_iterator::operator->() const
787
788 Returns a pointer to the current item.
789
790 \sa operator*()
791*/
792
793/*!
794 \fn template <class T> bool QSet<T>::iterator::operator==(const iterator &other) const
795 \fn template <class T> bool QSet<T>::const_iterator::operator==(const const_iterator &other) const
796
797 Returns \c true if \a other points to the same item as this
798 iterator; otherwise returns \c false.
799
800 \sa operator!=()
801*/
802
803/*!
804 \fn template <class T> bool QSet<T>::iterator::operator==(const const_iterator &other) const
805 \fn template <class T> bool QSet<T>::iterator::operator!=(const const_iterator &other) const
806
807 \overload
808*/
809
810/*!
811 \fn template <class T> bool QSet<T>::iterator::operator!=(const iterator &other) const
812 \fn template <class T> bool QSet<T>::const_iterator::operator!=(const const_iterator &other) const
813
814 Returns \c true if \a other points to a different item than this
815 iterator; otherwise returns \c false.
816
817 \sa operator==()
818*/
819
820/*!
821 \fn template <class T> QSet<T>::iterator &QSet<T>::iterator::operator++()
822 \fn template <class T> QSet<T>::const_iterator &QSet<T>::const_iterator::operator++()
823
824 The prefix ++ operator (\c{++it}) advances the iterator to the
825 next item in the set and returns an iterator to the new current
826 item.
827
828 Calling this function on QSet<T>::constEnd() leads to
829 undefined results.
830*/
831
832/*!
833 \fn template <class T> QSet<T>::iterator QSet<T>::iterator::operator++(int)
834 \fn template <class T> QSet<T>::const_iterator QSet<T>::const_iterator::operator++(int)
835
836 \overload
837
838 The postfix ++ operator (\c{it++}) advances the iterator to the
839 next item in the set and returns an iterator to the previously
840 current item.
841*/
842
843/*! \fn template <class T> QList<T> QSet<T>::values() const
844
845 Returns a new QList containing the elements in the set. The
846 order of the elements in the QList is undefined.
847
848 \include containers-range-constructor.qdocinc
849
850 This function creates a new list, in \l {linear time}. The time and memory
851 use that entails can be avoided by iterating from \l constBegin() to
852 \l constEnd().
853*/
854
855
856/*!
857 \fn template <class T> QDataStream &operator<<(QDataStream &out, const QSet<T> &set)
858 \relates QSet
859
860 Writes the \a set to stream \a out.
861
862 This function requires the value type to implement \c operator<<().
863
864 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
865*/
866
867/*!
868 \fn template <class T> QDataStream &operator>>(QDataStream &in, QSet<T> &set)
869 \relates QSet
870
871 Reads a set from stream \a in into \a set.
872
873 This function requires the value type to implement \c operator>>().
874
875 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
876*/
877
878/*!
879 \fn template <class T> size_t qHash(const QSet<T> &key, size_t seed = 0)
880 \qhasholdT{QHash}{T}
881 \since 5.5
882
883 The hash value is independent of the order of elements in \a key, that is, sets
884 that contain the same elements hash to the same value.
885*/
886
887/*! \fn template <class T, class Predicate> qsizetype erase_if(QSet<T> &set, Predicate pred)
888 \relates QSet
889 \since 6.1
890
891 Removes all elements for which the predicate \a pred returns true
892 from the set \a set. Returns the number of elements removed, if
893 any.
894*/
895
896/*! \fn template <class T> template <class Pred> qsizetype QSet<T>::removeIf(Pred pred)
897 \since 6.1
898
899 Removes, from this set, all elements for which the predicate \a pred
900 returns \c true. Returns the number of elements removed, if any.
901*/