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
qmap.qdoc
Go to the documentation of this file.
1// Copyright (C) 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2// Copyright (C) 2016 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
4
5/*!
6 \class QMap
7 \inmodule QtCore
8 \brief The QMap class is a template class that provides an associative array.
9 \compares equality
10
11 \ingroup tools
12 \ingroup shared
13
14 \reentrant
15
16 QMap<Key, T> is one of Qt's generic \l{container classes}, where
17 \a Key is the type used for lookup keys and \a T is the mapped value
18 type. It stores (key, value) pairs and provides fast lookup by key.
19
20 QMap and QHash provide very similar functionality. The
21 differences are:
22
23 \list
24 \li QHash provides average faster lookups than QMap. (See \l{Algorithmic
25 Complexity} for details.)
26 \li When iterating over a QHash, the items are arbitrarily ordered.
27 With QMap, the items are always sorted by key.
28 \li The key type of a QHash must provide operator==() and a global
29 qHash(Key) function. The key type of a QMap must provide
30 operator<() specifying a total order. Since Qt 5.8.1 it is also safe
31 to use a pointer type as key, even if the underlying operator<()
32 does not provide a total order.
33 \endlist
34
35 Here's an example QMap with QString keys and \c int values:
36 \snippet code/src_corelib_tools_qmap.cpp 0
37
38 To insert a (key, value) pair into the map, you can use operator[]():
39
40 \snippet code/src_corelib_tools_qmap.cpp 1
41
42 This inserts the following three (key, value) pairs into the
43 QMap: ("one", 1), ("three", 3), and ("seven", 7). Another way to
44 insert items into the map is to use insert():
45
46 \snippet code/src_corelib_tools_qmap.cpp 2
47
48 To look up a value, use operator[]() or value():
49
50 \snippet code/src_corelib_tools_qmap.cpp 3
51
52 If there is no item with the specified key in the map, these
53 functions return a \l{default-constructed value}.
54
55 If you want to check whether the map contains a certain key, use
56 contains():
57
58 \snippet code/src_corelib_tools_qmap.cpp 4
59
60 There is also a value() overload that uses its second argument as
61 a default value if there is no item with the specified key:
62
63 \snippet code/src_corelib_tools_qmap.cpp 5
64
65 In general, we recommend that you use contains() and value()
66 rather than operator[]() for looking up a key in a map. The
67 reason is that operator[]() silently inserts an item into the
68 map if no item exists with the same key (unless the map is
69 const). For example, the following code snippet will create 1000
70 items in memory:
71
72 \snippet code/src_corelib_tools_qmap.cpp 6
73
74 To avoid this problem, replace \c map[i] with \c map.value(i)
75 in the code above.
76
77 If you want to navigate through all the (key, value) pairs stored
78 in a QMap, you can use an iterator. QMap provides both
79 \l{Java-style iterators} (QMapIterator and QMutableMapIterator)
80 and \l{STL-style iterators} (QMap::const_iterator and
81 QMap::iterator). Here's how to iterate over a QMap<QString, int>
82 using a Java-style iterator:
83
84 \snippet code/src_corelib_tools_qmap.cpp 7
85
86 Here's the same code, but using an STL-style iterator this time:
87
88 \snippet code/src_corelib_tools_qmap.cpp 8
89
90 The items are traversed in ascending key order.
91
92 A QMap allows only one value per key. If you call
93 insert() with a key that already exists in the QMap, the
94 previous value will be erased. For example:
95
96 \snippet code/src_corelib_tools_qmap.cpp 9
97
98 However, you can store multiple values per key by using
99 QMultiMap.
100
101 If you only need to extract the values from a map (not the keys),
102 you can also use range-based for:
103
104 \snippet code/src_corelib_tools_qmap.cpp 12
105
106 Items can be removed from the map in several ways. One way is to
107 call remove(); this will remove any item with the given key.
108 Another way is to use QMutableMapIterator::remove(). In addition,
109 you can clear the entire map using clear().
110
111 QMap's key and value data types must be \l{assignable data
112 types}. This covers most data types you are likely to encounter,
113 but the compiler won't let you, for example, store a QWidget as a
114 value; instead, store a QWidget *. In addition, QMap's key type
115 must provide operator<(). QMap uses it to keep its items sorted,
116 and assumes that two keys \c x and \c y are equivalent if neither \c{x
117 < y} nor \c{y < x} is true.
118
119 Example:
120 \snippet code/src_corelib_tools_qmap.cpp 13
121
122 In the example, we start by comparing the employees' names. If
123 they're equal, we compare their dates of birth to break the tie.
124
125 \sa QMapIterator, QMutableMapIterator, QHash, QSet
126*/
127
128/*! \fn template <class Key, class T> QMap<Key, T>::QMap()
129
130 Constructs an empty map.
131
132 \sa clear()
133*/
134
135/*! \fn template <class Key, class T> QMap<Key, T>::QMap(const QMap<Key, T> &other)
136
137 Constructs a copy of \a other.
138
139 This operation occurs in \l{constant time}, because QMap is
140 \l{implicitly shared}. This makes returning a QMap from a
141 function very fast. If a shared instance is modified, it will be
142 copied (copy-on-write), and this takes \l{linear time}.
143
144 \sa operator=
145*/
146
147/*!
148 \fn template <class Key, class T> QMap<Key, T>::QMap(QMap<Key, T> &&other)
149
150 Move-constructs a QMap instance.
151
152 \since 5.2
153*/
154
155/*! \fn template <class Key, class T> QMap<Key, T> &QMap<Key, T>::operator=(const QMap<Key, T> &other)
156
157 Assigns \a other to this map and returns a reference to this map.
158*/
159
160/*!
161 \fn template <class Key, class T> QMap<Key, T> &QMap<Key, T>::operator=(QMap<Key, T> &&other)
162
163 Move-assigns \a other to this QMap instance.
164
165 \since 5.2
166*/
167
168/*! \fn template <class Key, class T> QMap<Key, T>::~QMap()
169
170 Destroys the map. References to the values in the map, and all
171 iterators over this map, become invalid.
172*/
173
174/*! \fn template <class Key, class T> void QMap<Key, T>::swap(QMap<Key, T> &other) noexcept
175 \since 4.8
176 \memberswap{map}
177*/
178
179/*! \fn template <class Key, class T> QMap<Key, T>::QMap(std::initializer_list<std::pair<Key,T> > list)
180 \since 5.1
181
182 Constructs a map with a copy of each of the elements in the
183 initializer list \a list.
184*/
185
186/*! \fn template <class Key, class T> QMap<Key, T>::QMap(const std::map<Key, T> & other)
187
188 Constructs a copy of \a other.
189
190 \sa toStdMap()
191*/
192
193/*! \fn template <class Key, class T> QMap<Key, T>::QMap(std::map<Key, T> && other)
194
195 Constructs a map by moving from \a other.
196
197 \sa toStdMap()
198*/
199
200/*! \fn template <class Key, class T> std::map<Key, T> QMap<Key, T>::toStdMap() const &
201
202 Returns an STL map equivalent to this QMap.
203*/
204
205/*! \fn template <class Key, class T> std::map<Key, T> QMap<Key, T>::toStdMap() &&
206
207 \overload
208 \since 6.0
209
210 \note Calling this function will leave this QMap in the partially-formed state, in which
211 the only valid operations are destruction or assignment of a new value.
212*/
213
214/*! \fn template <class Key, class T> bool QMap<Key, T>::operator==(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
215
216 Returns \c true if \a lhs is equal to \a rhs; otherwise returns
217 false.
218
219 Two maps are considered equal if they contain the same (key,
220 value) pairs.
221
222 This function requires the key and the value types to implement \c
223 operator==().
224
225 \sa operator!=()
226*/
227
228/*! \fn template <class Key, class T> bool QMap<Key, T>::operator!=(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
229
230 Returns \c true if \a lhs is not equal to \a rhs; otherwise returns
231 false.
232
233 Two maps are considered equal if they contain the same (key,
234 value) pairs.
235
236 This function requires the key and the value types to implement \c
237 operator==().
238
239 \sa operator==()
240*/
241
242/*! \fn template <class Key, class T> bool QMap<Key, T>::operator<(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
243 \since 6.12
244
245 Returns \c true if \a lhs is
246 \l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
247 {lexicographically less than} \a rhs; otherwise returns \c false.
248
249//! [operator_uses_qt_lex_compare_three_way]
250 This operator is available if both the key type \c Key and the mapped type
251 \c T provide one of \c {operator<=>()} (in C++20 mode),
252 \c {compareThreeWay()} helper method, or \c {operator<()}.
253//! [operator_uses_qt_lex_compare_three_way]
254*/
255
256/*! \fn template <class Key, class T> bool QMap<Key, T>::operator>(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
257 \since 6.12
258
259 Returns \c true if \a lhs is
260 \l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
261 {lexicographically greater than} \a rhs; otherwise returns \c false.
262
263 \include qmap.qdoc operator_uses_qt_lex_compare_three_way
264*/
265
266/*! \fn template <class Key, class T> bool QMap<Key, T>::operator<=(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
267 \since 6.12
268
269 Returns \c true if \a lhs is
270 \l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
271 {lexicographically less or equal than} \a rhs; otherwise returns \c false.
272
273 \include qmap.qdoc operator_uses_qt_lex_compare_three_way
274*/
275
276/*! \fn template <class Key, class T> bool QMap<Key, T>::operator>=(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
277 \since 6.12
278
279 Returns \c true if \a lhs is
280 \l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
281 {lexicographically greater or equal than} \a rhs; otherwise returns \c false.
282
283 \include qmap.qdoc operator_uses_qt_lex_compare_three_way
284*/
285
286/*! \fn template <class Key, class T> auto QMap<Key, T>::operator<=>(const QMap<Key, T> &lhs, const QMap<Key, T> &rhs)
287 \since 6.12
288
289 Compares the contents of \a lhs and \a rhs
290 \l {https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare_three_way}
291 {lexicographically}. Returns the result of the strongest applicable category
292 type.
293
294//! [operator_in_cpp20_only]
295 \note This operator is only available in C++20 mode when both the key type
296 \c Key and the mapped type \c T meet the requirements of
297 \c {std::three_way_comparable} concept or provide \c {operator<()}.
298 In this case the \c{<}, \c{<=}, \c{>}, and \c{>=} operators are synthesized
299 from \c {operator<=>()} and \c {operator==()}.
300//! [operator_in_cpp20_only]
301*/
302
303/*! \fn template <class Key, class T> size_type QMap<Key, T>::size() const
304
305 Returns the number of (key, value) pairs in the map.
306
307 \sa isEmpty(), count()
308*/
309
310/*!
311 \fn template <class Key, class T> bool QMap<Key, T>::isEmpty() const
312
313 Returns \c true if the map contains no items; otherwise returns
314 false.
315
316 \sa size()
317*/
318
319/*! \fn template <class Key, class T> void QMap<Key, T>::detach()
320
321 \internal
322
323 Detaches this map from any other maps with which it may share
324 data.
325
326 \sa isDetached()
327*/
328
329/*! \fn template <class Key, class T> bool QMap<Key, T>::isDetached() const
330
331 \internal
332
333 Returns \c true if the map's internal data isn't shared with any
334 other map object; otherwise returns \c false.
335
336 \sa detach()
337*/
338
339/*! \fn template <class Key, class T> bool QMap<Key, T>::isSharedWith(const QMap<Key, T> &other) const
340
341 \internal
342*/
343
344/*! \fn template <class Key, class T> void QMap<Key, T>::clear()
345
346 Removes all items from the map.
347
348 \sa remove()
349*/
350
351/*! \fn template <class Key, class T> size_type QMap<Key, T>::remove(const Key &key)
352
353 Removes all the items that have the key \a key from the map.
354 Returns the number of items removed which will be 1 if the key
355 exists in the map, and 0 otherwise.
356
357 \sa clear(), take()
358*/
359
360/*! \fn template <class Key, class T> template <typename Predicate> size_type QMap<Key, T>::removeIf(Predicate pred)
361 \since 6.1
362
363 Removes all elements for which the predicate \a pred returns true
364 from the map.
365
366 The function supports predicates which take either an argument of
367 type \c{QMap<Key, T>::iterator}, or an argument of type
368 \c{std::pair<const Key &, T &>}.
369
370 Returns the number of elements removed, if any.
371
372 \sa clear(), take()
373*/
374
375/*! \fn template <class Key, class T> T QMap<Key, T>::take(const Key &key)
376
377 Removes the item with the key \a key from the map and returns
378 the value associated with it.
379
380 If the item does not exist in the map, the function simply
381 returns a \l{default-constructed value}.
382
383 If you don't use the return value, remove() is more efficient.
384
385 \sa remove()
386*/
387
388/*! \fn template <class Key, class T> bool QMap<Key, T>::contains(const Key &key) const
389
390 Returns \c true if the map contains an item with key \a key;
391 otherwise returns \c false.
392
393 \sa count()
394*/
395
396/*!
397 \fn template <class Key, class T> Key QMap<Key, T>::key(const T &value, const Key &defaultKey) const
398 \since 4.3
399 \overload
400
401 Returns the first key with value \a value, or \a defaultKey if
402 the map contains no item with value \a value. If no \a defaultKey
403 is provided the function returns a
404 \l{default-constructed value}{default-constructed key}.
405
406 This function can be slow (\l{linear time}), because QMap's
407 internal data structure is optimized for fast lookup by key, not
408 by value.
409
410 \sa value(), keys()
411*/
412
413/*! \fn template <class Key, class T> T QMap<Key, T>::value(const Key &key, const T &defaultValue) const
414
415 Returns the value associated with the key \a key.
416
417 If the map contains no item with key \a key, the function returns
418 \a defaultValue. If no \a defaultValue is specified, the function
419 returns a \l{default-constructed value}.
420
421 \sa key(), values(), contains(), operator[]()
422*/
423
424/*! \fn template <class Key, class T> T &QMap<Key, T>::operator[](const Key &key)
425
426 Returns the value associated with the key \a key as a modifiable
427 reference.
428
429 If the map contains no item with key \a key, the function inserts
430 a \l{default-constructed value} into the map with key \a key, and
431 returns a reference to it.
432
433 \sa insert(), value()
434*/
435
436/*! \fn template <class Key, class T> T QMap<Key, T>::operator[](const Key &key) const
437
438 \overload
439
440 Same as value().
441*/
442
443/*! \fn template <class Key, class T> QList<Key> QMap<Key, T>::keys() const
444
445 Returns a list containing all the keys in the map in ascending
446 order.
447
448 The order is guaranteed to be the same as that used by values().
449
450 This function creates a new list, in \l {linear time}. The time and memory
451 use that entails can be avoided by iterating from \l keyBegin() to
452 \l keyEnd().
453
454 \sa values(), key()
455*/
456
457/*! \fn template <class Key, class T> QList<Key> QMap<Key, T>::keys(const T &value) const
458
459 \overload
460
461 Returns a list containing all the keys associated with value \a
462 value in ascending order.
463
464 This function can be slow (\l{linear time}), because QMap's
465 internal data structure is optimized for fast lookup by key, not
466 by value.
467*/
468
469/*! \fn template <class Key, class T> QList<T> QMap<Key, T>::values() const
470
471 Returns a list containing all the values in the map, in ascending
472 order of their keys.
473
474 This function creates a new list, in \l {linear time}. The time and memory
475 use that entails can be avoided by iterating from \l keyValueBegin() to
476 \l keyValueEnd().
477
478 \sa keys(), value()
479*/
480
481/*! \fn template <class Key, class T> size_type QMap<Key, T>::count(const Key &key) const
482
483 Returns the number of items associated with key \a key.
484
485 \sa contains()
486*/
487
488/*! \fn template <class Key, class T> size_type QMap<Key, T>::count() const
489
490 \overload
491
492 Same as size().
493*/
494
495/*! \fn template <class Key, class T> const Key &QMap<Key, T>::firstKey() const
496 \since 5.2
497
498 Returns a reference to the smallest key in the map.
499 This function assumes that the map is not empty.
500
501 This executes in \l{constant time}.
502
503 \sa lastKey(), first(), keyBegin(), isEmpty()
504*/
505
506/*! \fn template <class Key, class T> const Key &QMap<Key, T>::lastKey() const
507 \since 5.2
508
509 Returns a reference to the largest key in the map.
510 This function assumes that the map is not empty.
511
512 This executes in \l{constant time}.
513
514 \sa firstKey(), last(), keyEnd(), isEmpty()
515*/
516
517/*! \fn template <class Key, class T> T &QMap<Key, T>::first()
518 \since 5.2
519
520 Returns a reference to the first value in the map, that is the value mapped
521 to the smallest key. This function assumes that the map is not empty.
522
523 When unshared (or const version is called), this executes in \l{constant time}.
524
525 \sa last(), firstKey(), isEmpty()
526*/
527
528/*! \fn template <class Key, class T> const T &QMap<Key, T>::first() const
529 \since 5.2
530
531 \overload
532*/
533
534/*! \fn template <class Key, class T> T &QMap<Key, T>::last()
535 \since 5.2
536
537 Returns a reference to the last value in the map, that is the value mapped
538 to the largest key. This function assumes that the map is not empty.
539
540 When unshared (or const version is called), this executes in \l{constant time}.
541
542 \sa first(), lastKey(), isEmpty()
543*/
544
545/*! \fn template <class Key, class T> const T &QMap<Key, T>::last() const
546 \since 5.2
547
548 \overload
549*/
550
551/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::begin()
552
553 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in
554 the map.
555
556 \sa constBegin(), end()
557*/
558
559/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::begin() const
560
561 \overload
562*/
563
564/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::cbegin() const
565 \since 5.0
566
567 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
568 in the map.
569
570 \sa begin(), cend()
571*/
572
573/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::constBegin() const
574
575 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
576 in the map.
577
578 \sa begin(), constEnd()
579*/
580
581/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator QMap<Key, T>::keyBegin() const
582 \since 5.6
583
584 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first key
585 in the map.
586
587 \sa keyEnd(), firstKey()
588*/
589
590/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::end()
591
592 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
593 after the last item in the map.
594
595 \sa begin(), constEnd()
596*/
597
598/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::end() const
599
600 \overload
601*/
602
603/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::cend() const
604 \since 5.0
605
606 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
607 item after the last item in the map.
608
609 \sa cbegin(), end()
610*/
611
612/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::constEnd() const
613
614 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
615 item after the last item in the map.
616
617 \sa constBegin(), end()
618*/
619
620/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator QMap<Key, T>::keyEnd() const
621 \since 5.6
622
623 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
624 item after the last key in the map.
625
626 \sa keyBegin(), lastKey()
627*/
628
629
630/*! \fn template <class Key, class T> QMap<Key, T>::key_value_iterator QMap<Key, T>::keyValueBegin()
631 \since 5.10
632
633 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first entry
634 in the map.
635
636 \sa keyValueEnd()
637*/
638
639/*! \fn template <class Key, class T> QMap<Key, T>::key_value_iterator QMap<Key, T>::keyValueEnd()
640 \since 5.10
641
642 Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
643 entry after the last entry in the map.
644
645 \sa keyValueBegin()
646*/
647
648/*! \fn template <class Key, class T> QMap<Key, T>::const_key_value_iterator QMap<Key, T>::keyValueBegin() const
649 \since 5.10
650
651 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry
652 in the map.
653
654 \sa keyValueEnd()
655*/
656
657/*! \fn template <class Key, class T> QMap<Key, T>::const_key_value_iterator QMap<Key, T>::constKeyValueBegin() const
658 \since 5.10
659
660 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry
661 in the map.
662
663 \sa keyValueBegin()
664*/
665
666/*! \fn template <class Key, class T> QMap<Key, T>::const_key_value_iterator QMap<Key, T>::keyValueEnd() const
667 \since 5.10
668
669 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
670 entry after the last entry in the map.
671
672 \sa keyValueBegin()
673*/
674
675/*! \fn template <class Key, class T> QMap<Key, T>::const_key_value_iterator QMap<Key, T>::constKeyValueEnd() const
676 \since 5.10
677
678 Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
679 entry after the last entry in the map.
680
681 \sa constKeyValueBegin()
682*/
683
684/*! \fn template <class Key, class T> auto QMap<Key, T>::asKeyValueRange() &
685 \fn template <class Key, class T> auto QMap<Key, T>::asKeyValueRange() const &
686 \fn template <class Key, class T> auto QMap<Key, T>::asKeyValueRange() &&
687 \fn template <class Key, class T> auto QMap<Key, T>::asKeyValueRange() const &&
688 \since 6.4
689
690 Returns a range object that allows iteration over this map as
691 key/value pairs. For instance, this range object can be used in a
692 range-based for loop, in combination with a structured binding declaration:
693
694 \snippet code/src_corelib_tools_qmap.cpp 28
695
696 Note that both the key and the value obtained this way are
697 references to the ones in the map. Specifically, mutating the value
698 will modify the map itself.
699
700 \sa QKeyValueIterator
701*/
702
703/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::erase(const_iterator pos)
704
705 Removes the (key, value) pair pointed to by the iterator \a pos
706 from the map, and returns an iterator to the next item in the
707 map.
708
709 \note The iterator \a pos \e must be valid and dereferenceable.
710
711 \sa remove()
712*/
713
714/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::erase(const_iterator first, const_iterator last)
715 \since 6.0
716
717 Removes the (key, value) pairs pointed to by the iterator range
718 [\a first, \a last) from the map.
719 Returns an iterator to the item in the map following the last removed element.
720
721 \note The range \c {[first, last)} \e must be a valid range in \c {*this}.
722
723 \sa remove()
724*/
725
726/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::find(const Key &key)
727
728 Returns an iterator pointing to the item with key \a key in the
729 map.
730
731 If the map contains no item with key \a key, the function
732 returns end().
733
734 \sa constFind(), value(), values(), lowerBound(), upperBound()
735*/
736
737/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::find(const Key &key) const
738
739 \overload
740*/
741
742/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::constFind(const Key &key) const
743 \since 4.1
744
745 Returns an const iterator pointing to the item with key \a key in the
746 map.
747
748 If the map contains no item with key \a key, the function
749 returns constEnd().
750
751 \sa find()
752*/
753
754/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::lowerBound(const Key &key)
755
756 Returns an iterator pointing to the first item with key \a key in
757 the map. If the map contains no item with key \a key, the
758 function returns an iterator to the nearest item with a greater
759 key.
760
761 \sa upperBound(), find()
762*/
763
764/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::lowerBound(const Key &key) const
765
766 \overload
767*/
768
769/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::upperBound(const Key &key)
770
771 Returns an iterator pointing to the item that immediately follows
772 the last item with key \a key in the map. If the map contains no
773 item with key \a key, the function returns an iterator to the
774 nearest item with a greater key.
775
776 Example:
777 \snippet code/src_corelib_tools_qmap.cpp 17
778
779 \sa lowerBound(), find()
780*/
781
782/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::upperBound(const Key &key) const
783
784 \overload
785*/
786
787/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::insert(const Key &key, const T &value)
788
789 Inserts a new item with the key \a key and a value of \a value.
790
791 If there is already an item with the key \a key, that item's value
792 is replaced with \a value.
793
794 Returns an iterator pointing to the new/updated element.
795*/
796
797/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::insert(const_iterator pos, const Key &key, const T &value)
798 \overload
799 \since 5.1
800 Inserts a new item with the key \a key and value \a value and with hint \a pos
801 suggesting where to do the insert.
802
803 If constBegin() is used as hint it indicates that the \a key is less than any key in the map
804 while constEnd() suggests that the \a key is (strictly) larger than any key in the map.
805 Otherwise the hint should meet the condition (\a pos - 1).key() < \a key <= pos.key().
806 If the hint \a pos is wrong it is ignored and a regular insert is done.
807
808 If there is already an item with the key \a key, that item's value
809 is replaced with \a value.
810
811 If the hint is correct and the map is unshared, the insert executes in amortized \l{constant time}.
812
813 When creating a map from sorted data inserting the largest key first with constBegin()
814 is faster than inserting in sorted order with constEnd(), since constEnd() - 1 (which is needed
815 to check if the hint is valid) needs \l{logarithmic time}.
816
817 \b {Note:} Be careful with the hint. Providing an iterator from an older shared instance might
818 crash but there is also a risk that it will silently corrupt both the map and the \a pos map.
819
820 Returns an iterator pointing to the new/updated element.
821*/
822
823/*! \fn template <class Key, class T> void QMap<Key, T>::insert(const QMap<Key, T> &map)
824 \since 5.15
825
826 Inserts all the items in \a map into this map.
827
828 If a key is common to both maps, its value will be replaced with
829 the value stored in \a map.
830*/
831
832/*! \fn template <class Key, class T> void QMap<Key, T>::insert(QMap<Key, T> &&map)
833 \since 5.15
834
835 Moves all the items from \a map into this map.
836
837 If a key is common to both maps, its value will be replaced with
838 the value stored in \a map.
839
840 If \a map is shared, then the items will be copied instead.
841*/
842
843/*! \typedef QMap::Iterator
844
845 Qt-style synonym for QMap::iterator.
846*/
847
848/*! \typedef QMap::ConstIterator
849
850 Qt-style synonym for QMap::const_iterator.
851*/
852
853/*! \typedef QMap::difference_type
854
855 Typedef for ptrdiff_t. Provided for STL compatibility.
856*/
857
858/*! \typedef QMap::key_type
859
860 Typedef for Key. Provided for STL compatibility.
861*/
862
863/*! \typedef QMap::mapped_type
864
865 Typedef for T. Provided for STL compatibility.
866*/
867
868/*! \typedef QMap::size_type
869
870 Typedef for int. Provided for STL compatibility.
871*/
872
873/*!
874 \fn template <class Key, class T> bool QMap<Key, T>::empty() const
875
876 This function is provided for STL compatibility. It is equivalent
877 to isEmpty(), returning true if the map is empty; otherwise
878 returning false.
879*/
880
881/*!
882 \fn template <class Key, class T> std::pair<typename QMap<Key, T>::iterator, typename QMap<Key, T>::iterator> QMap<Key, T>::equal_range(const Key &key)
883
884 Returns a pair of iterators delimiting the range of values \c{[first, second)}, that
885 are stored under \a key.
886*/
887
888/*!
889 \fn template <class Key, class T> std::pair<typename QMap<Key, T>::const_iterator, typename QMap<Key, T>::const_iterator> QMap<Key, T>::equal_range(const Key &key) const
890 \overload
891 \since 5.6
892*/
893
894
895/*! \class QMap::iterator
896 \inmodule QtCore
897 \brief The QMap::iterator class provides an STL-style non-const iterator for QMap.
898
899 QMap<Key, T>::iterator allows you to iterate over a QMap
900 and to modify the value (but not the key) stored under
901 a particular key. If you want to iterate over a const QMap, you
902 should use QMap::const_iterator. It is generally good practice to
903 use QMap::const_iterator on a non-const QMap as well, unless you
904 need to change the QMap through the iterator. Const iterators are
905 slightly faster, and can improve code readability.
906
907 The default QMap::iterator constructor creates an uninitialized
908 iterator. You must initialize it using a QMap function like
909 QMap::begin(), QMap::end(), or QMap::find() before you can
910 start iterating. Here's a typical loop that prints all the (key,
911 value) pairs stored in a map:
912
913 \snippet code/src_corelib_tools_qmap.cpp 18
914
915 Unlike QHash, which stores its items in an arbitrary order, QMap
916 stores its items ordered by key.
917
918 Here's an example that increments every value stored in the QMap
919 by 2:
920
921 \snippet code/src_corelib_tools_qmap.cpp 19
922
923 To remove elements from a QMap you can use erase_if(QMap<Key, T> &map, Predicate pred):
924
925 \snippet code/src_corelib_tools_qmap.cpp 21
926
927 Multiple iterators can be used on the same map. If you add items
928 to the map, existing iterators will remain valid. If you remove
929 items from the map, iterators that point to the removed items
930 will become dangling iterators.
931
932 \warning Iterators on implicitly shared containers do not work
933 exactly like STL-iterators. You should avoid copying a container
934 while iterators are active on that container. For more information,
935 read \l{Implicit sharing iterator problem}.
936
937 \sa QMap::const_iterator, QMap::key_iterator, QMap::key_value_iterator
938*/
939
940/*! \typedef QMap::iterator::difference_type
941
942 \internal
943*/
944
945/*! \typedef QMap::iterator::iterator_category
946
947 A synonym for \e {std::bidirectional_iterator_tag} indicating
948 this iterator is a bidirectional iterator.
949*/
950
951/*! \typedef QMap::iterator::pointer
952
953 \internal
954*/
955
956/*! \typedef QMap::iterator::reference
957
958 \internal
959*/
960
961/*! \typedef QMap::iterator::value_type
962
963 \internal
964*/
965
966/*! \fn template <class Key, class T> QMap<Key, T>::iterator::iterator()
967
968 Constructs an uninitialized iterator.
969
970 Functions like key(), value(), and operator++() must not be
971 called on an uninitialized iterator. Use operator=() to assign a
972 value to it before using it.
973
974 \sa QMap::begin(), QMap::end()
975*/
976
977/*! \fn template <class Key, class T> const Key &QMap<Key, T>::iterator::key() const
978
979 Returns the current item's key as a const reference.
980
981 There is no direct way of changing an item's key through an
982 iterator, although it can be done by calling QMap::erase()
983 followed by QMap::insert().
984
985 \sa value()
986*/
987
988/*! \fn template <class Key, class T> T &QMap<Key, T>::iterator::value() const
989
990 Returns a modifiable reference to the current item's value.
991
992 You can change the value of an item by using value() on
993 the left side of an assignment, for example:
994
995 \snippet code/src_corelib_tools_qmap.cpp 23
996
997 \sa key(), operator*()
998*/
999
1000/*! \fn template <class Key, class T> T &QMap<Key, T>::iterator::operator*() const
1001
1002 Returns a modifiable reference to the current item's value.
1003
1004 Same as value().
1005
1006 \sa key()
1007*/
1008
1009/*! \fn template <class Key, class T> T *QMap<Key, T>::iterator::operator->() const
1010
1011 Returns a pointer to the current item's value.
1012
1013 \sa value()
1014*/
1015
1016/*!
1017 \fn template <class Key, class T> bool QMap<Key, T>::iterator::operator==(const iterator &lhs, const iterator &rhs)
1018 \fn template <class Key, class T> bool QMap<Key, T>::const_iterator::operator==(const const_iterator &lhs, const const_iterator &rhs)
1019
1020 Returns \c true if \a lhs points to the same item as the \a rhs iterator;
1021 otherwise returns \c false.
1022
1023 \sa operator!=()
1024*/
1025
1026/*!
1027 \fn template <class Key, class T> bool QMap<Key, T>::iterator::operator!=(const iterator &lhs, const iterator &rhs)
1028 \fn template <class Key, class T> bool QMap<Key, T>::const_iterator::operator!=(const const_iterator &lhs, const const_iterator &rhs)
1029
1030 Returns \c true if \a lhs points to a different item than the \a rhs iterator;
1031 otherwise returns \c false.
1032
1033 \sa operator==()
1034*/
1035
1036/*! \fn template <class Key, class T> QMap<Key, T>::iterator &QMap<Key, T>::iterator::operator++()
1037
1038 The prefix \c{++} operator (\c{++i}) advances the iterator to the
1039 next item in the map and returns an iterator to the new current
1040 item.
1041
1042 Calling this function on QMap::end() leads to undefined results.
1043
1044 \sa operator--()
1045*/
1046
1047/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::iterator::operator++(int)
1048
1049 \overload
1050
1051 The postfix \c{++} operator (\c{i++}) advances the iterator to the
1052 next item in the map and returns an iterator to the previously
1053 current item.
1054*/
1055
1056/*! \fn template <class Key, class T> QMap<Key, T>::iterator &QMap<Key, T>::iterator::operator--()
1057
1058 The prefix \c{--} operator (\c{--i}) makes the preceding item
1059 current and returns an iterator pointing to the new current item.
1060
1061 Calling this function on QMap::begin() leads to undefined
1062 results.
1063
1064 \sa operator++()
1065*/
1066
1067/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::iterator::operator--(int)
1068
1069 \overload
1070
1071 The postfix \c{--} operator (\c{i--}) makes the preceding item
1072 current and returns an iterator pointing to the previously
1073 current item.
1074*/
1075
1076/*! //! friends
1077 \fn [qmap-op-it-plus-step] template <class Key, class T> typename QMap<Key, T>::iterator QMap<Key, T>::iterator::operator+(QMap<Key, T>::iterator, difference_type n)
1078 \fn [qmap-op-step-plus-it] template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::iterator::operator+(difference_type n, QMap<Key, T>::iterator)
1079 \fn [qmap-op-it-minus-step] template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::iterator::operator-(QMap<Key, T>::iterator, difference_type n)
1080 \fn [qmap-op-step-minus-it] template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::iterator::operator-(difference_type n, QMap<Key, T>::iterator)
1081
1082 //! members
1083 \fn template <class Key, class T> typename QMap<Key, T>::iterator QMap<Key, T>::iterator::operator+=(QMap<Key, T>::iterator::difference_type n)
1084 \fn template <class Key, class T> typename QMap<Key, T>::iterator QMap<Key, T>::iterator::operator-=(QMap<Key, T>::iterator::difference_type n)
1085
1086 \deprecated [6.2] Use \c{std::next}, \c{std::prev} or \c{std::advance} instead.
1087
1088 Moves an iterator by \e{n} positions. These operations can be
1089 expensive for large values of \e{n}; QMap iterators are not
1090 random access.
1091*/
1092
1093/*! \class QMap::const_iterator
1094 \inmodule QtCore
1095 \brief The QMap::const_iterator class provides an STL-style const iterator for QMap.
1096
1097 QMap<Key, T>::const_iterator allows you to iterate over a QMap.
1098 If you want to modify the QMap as you iterate
1099 over it, you must use QMap::iterator instead. It is generally
1100 good practice to use QMap::const_iterator on a non-const QMap as
1101 well, unless you need to change the QMap through the iterator.
1102 Const iterators are slightly faster, and can improve code
1103 readability.
1104
1105 The default QMap::const_iterator constructor creates an
1106 uninitialized iterator. You must initialize it using a QMap
1107 function like QMap::cbegin(), QMap::cend(), or
1108 QMap::constFind() before you can start iterating. Here's a typical
1109 loop that prints all the (key, value) pairs stored in a map:
1110
1111 \snippet code/src_corelib_tools_qmap.cpp 24
1112
1113 Here's an example that removes all the items whose value is greater than 10:
1114
1115 \snippet code/src_corelib_tools_qmap.cpp 20
1116
1117 And here the same behavior with erase_if()
1118
1119 \snippet code/src_corelib_tools_qmap.cpp 21
1120
1121 Unlike QHash, which stores its items in an arbitrary order, QMap
1122 stores its items ordered by key.
1123
1124 Multiple iterators can be used on the same map. If you add items
1125 to the map, existing iterators will remain valid. If you remove
1126 items from the map, iterators that point to the removed items
1127 will become dangling iterators.
1128
1129 \warning Iterators on implicitly shared containers do not work
1130 exactly like STL-iterators. You should avoid copying a container
1131 while iterators are active on that container. For more information,
1132 read \l{Implicit sharing iterator problem}.
1133
1134 \sa QMap::iterator, QMap::key_iterator, QMap::const_key_value_iterator
1135*/
1136
1137/*! \typedef QMap::const_iterator::difference_type
1138
1139 \internal
1140*/
1141
1142/*! \typedef QMap::const_iterator::iterator_category
1143
1144 A synonym for \e {std::bidirectional_iterator_tag} indicating
1145 this iterator is a bidirectional iterator.
1146*/
1147
1148/*! \typedef QMap::const_iterator::pointer
1149
1150 \internal
1151*/
1152
1153/*! \typedef QMap::const_iterator::reference
1154
1155 \internal
1156*/
1157
1158/*! \typedef QMap::const_iterator::value_type
1159
1160 \internal
1161*/
1162
1163/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator::const_iterator()
1164
1165 Constructs an uninitialized iterator.
1166
1167 Functions like key(), value(), and operator++() must not be
1168 called on an uninitialized iterator. Use operator=() to assign a
1169 value to it before using it.
1170
1171 \sa QMap::constBegin(), QMap::constEnd()
1172*/
1173
1174/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator::const_iterator(const iterator &other)
1175
1176 Constructs a copy of \a other.
1177*/
1178
1179/*! \fn template <class Key, class T> const Key &QMap<Key, T>::const_iterator::key() const
1180
1181 Returns the current item's key.
1182
1183 \sa value()
1184*/
1185
1186/*! \fn template <class Key, class T> const T &QMap<Key, T>::const_iterator::value() const
1187
1188 Returns the current item's value.
1189
1190 \sa key(), operator*()
1191*/
1192
1193/*! \fn template <class Key, class T> const T &QMap<Key, T>::const_iterator::operator*() const
1194
1195 Returns the current item's value.
1196
1197 Same as value().
1198
1199 \sa key()
1200*/
1201
1202/*! \fn template <class Key, class T> const T *QMap<Key, T>::const_iterator::operator->() const
1203
1204 Returns a pointer to the current item's value.
1205
1206 \sa value()
1207*/
1208
1209/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator &QMap<Key, T>::const_iterator::operator++()
1210
1211 The prefix \c{++} operator (\c{++i}) advances the iterator to the
1212 next item in the map and returns an iterator to the new current
1213 item.
1214
1215 Calling this function on QMap::end() leads to undefined results.
1216
1217 \sa operator--()
1218*/
1219
1220/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::const_iterator::operator++(int)
1221
1222 \overload
1223
1224 The postfix \c{++} operator (\c{i++}) advances the iterator to the
1225 next item in the map and returns an iterator to the previously
1226 current item.
1227*/
1228
1229/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator &QMap<Key, T>::const_iterator::operator--()
1230
1231 The prefix \c{--} operator (\c{--i}) makes the preceding item
1232 current and returns an iterator pointing to the new current item.
1233
1234 Calling this function on QMap::begin() leads to undefined
1235 results.
1236
1237 \sa operator++()
1238*/
1239
1240/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::const_iterator::operator--(int)
1241
1242 \overload
1243
1244 The postfix \c{--} operator (\c{i--}) makes the preceding item
1245 current and returns an iterator pointing to the previously
1246 current item.
1247*/
1248
1249/*! //! friends
1250 \fn [qmap-op-it-plus-step-const] template <class Key, class T> QMap<Key, T>::const_iterator::operator+(QMap<Key, T>::const_iterator, difference_type n)
1251 \fn [qmap-op-step-plus-it-const] template <class Key, class T> QMap<Key, T>::operator+(difference_type n, QMap<Key, T>::const_iterator)
1252 \fn [qmap-op-it-minus-step-const] template <class Key, class T> QMap<Key, T>::operator-(QMap<Key, T>::const_iterator, difference_type n)
1253 \fn [qmap-op-step-minus-it-const] template <class Key, class T> QMap<Key, T>::operator-(difference_type n, QMap<Key, T>::const_iterator)
1254
1255 //! members
1256 \fn template <class Key, class T> typename QMap<Key, T>::const_iterator QMap<Key, T>::const_iterator::operator+=(QMap<Key, T>::const_iterator::difference_type n)
1257 \fn template <class Key, class T> typename QMap<Key, T>::const_iterator QMap<Key, T>::const_iterator::operator-=(QMap<Key, T>::const_iterator::difference_type n)
1258
1259 \deprecated [6.2] Use \c{std::next}, \c{std::prev} or \c{std::advance} instead.
1260
1261 Moves an iterator by \e{n} positions. These operations can be
1262 expensive for large values of \e{n}. QMap iterators are not
1263 random access.
1264*/
1265
1266/*! \class QMap::key_iterator
1267 \inmodule QtCore
1268 \since 5.6
1269 \brief The QMap::key_iterator class provides an STL-style const iterator for QMap keys.
1270
1271 QMap::key_iterator is essentially the same as QMap::const_iterator
1272 with the difference that operator*() and operator->() return a key
1273 instead of a value.
1274
1275 For most uses QMap::iterator and QMap::const_iterator should be used,
1276 you can easily access the key by calling QMap::iterator::key():
1277
1278 \snippet code/src_corelib_tools_qmap.cpp keyiterator1
1279
1280 However, to have interoperability between QMap's keys and STL-style
1281 algorithms we need an iterator that dereferences to a key instead
1282 of a value. With QMap::key_iterator we can apply an algorithm to a
1283 range of keys without having to call QMap::keys(), which is inefficient
1284 as it costs one QMap iteration and memory allocation to create a temporary
1285 QList.
1286
1287 \snippet code/src_corelib_tools_qmap.cpp keyiterator2
1288
1289 QMap::key_iterator is const, it's not possible to modify the key.
1290
1291 The default QMap::key_iterator constructor creates an uninitialized
1292 iterator. You must initialize it using a QMap function like
1293 QMap::keyBegin() or QMap::keyEnd().
1294
1295 \warning Iterators on implicitly shared containers do not work
1296 exactly like STL-iterators. You should avoid copying a container
1297 while iterators are active on that container. For more information,
1298 read \l{Implicit sharing iterator problem}.
1299
1300 \sa QMap::const_iterator, QMap::iterator
1301*/
1302
1303/*! \typedef QMap::key_iterator::difference_type
1304 \internal
1305*/
1306
1307/*! \typedef QMap::key_iterator::iterator_category
1308 \internal
1309*/
1310
1311/*! \typedef QMap::key_iterator::pointer
1312 \internal
1313*/
1314
1315/*! \typedef QMap::key_iterator::reference
1316 \internal
1317*/
1318
1319/*! \typedef QMap::key_iterator::value_type
1320 \internal
1321*/
1322
1323/*! \fn template <class Key, class T> const T &QMap<Key, T>::key_iterator::operator*() const
1324
1325 Returns the current item's key.
1326*/
1327
1328/*! \fn template <class Key, class T> const T *QMap<Key, T>::key_iterator::operator->() const
1329
1330 Returns a pointer to the current item's key.
1331*/
1332
1333/*! \fn template <class Key, class T> bool QMap<Key, T>::key_iterator::operator==(key_iterator other) const
1334
1335 Returns \c true if \a other points to the same item as this
1336 iterator; otherwise returns \c false.
1337
1338 \sa operator!=()
1339*/
1340
1341/*! \fn template <class Key, class T> bool QMap<Key, T>::key_iterator::operator!=(key_iterator other) const
1342
1343 Returns \c true if \a other points to a different item than this
1344 iterator; otherwise returns \c false.
1345
1346 \sa operator==()
1347*/
1348
1349/*!
1350 \fn template <class Key, class T> QMap<Key, T>::key_iterator &QMap<Key, T>::key_iterator::operator++()
1351
1352 The prefix \c{++} operator (\c{++i}) advances the iterator to the
1353 next item in the hash and returns an iterator to the new current
1354 item.
1355
1356 Calling this function on QMap::keyEnd() leads to undefined results.
1357
1358 \sa operator--()
1359*/
1360
1361/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator QMap<Key, T>::key_iterator::operator++(int)
1362
1363 \overload
1364
1365 The postfix \c{++} operator (\c{i++}) advances the iterator to the
1366 next item in the hash and returns an iterator to the previous
1367 item.
1368*/
1369
1370/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator &QMap<Key, T>::key_iterator::operator--()
1371
1372 The prefix \c{--} operator (\c{--i}) makes the preceding item
1373 current and returns an iterator pointing to the new current item.
1374
1375 Calling this function on QMap::keyBegin() leads to undefined
1376 results.
1377
1378 \sa operator++()
1379*/
1380
1381/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator QMap<Key, T>::key_iterator::operator--(int)
1382
1383 \overload
1384
1385 The postfix \c{--} operator (\c{i--}) makes the preceding item
1386 current and returns an iterator pointing to the previous
1387 item.
1388*/
1389
1390/*! \fn template <class Key, class T> const_iterator QMap<Key, T>::key_iterator::base() const
1391 Returns the underlying const_iterator this key_iterator is based on.
1392*/
1393
1394/*! \typedef QMap::const_key_value_iterator
1395 \inmodule QtCore
1396 \since 5.10
1397 \brief The QMap::const_key_value_iterator typedef provides an STL-style iterator for QMap.
1398
1399 QMap::const_key_value_iterator is essentially the same as QMap::const_iterator
1400 with the difference that operator*() returns a key/value pair instead of a
1401 value.
1402
1403 \sa QKeyValueIterator
1404*/
1405
1406/*! \typedef QMap::key_value_iterator
1407 \inmodule QtCore
1408 \since 5.10
1409 \brief The QMap::key_value_iterator typedef provides an STL-style iterator for QMap.
1410
1411 QMap::key_value_iterator is essentially the same as QMap::iterator
1412 with the difference that operator*() returns a key/value pair instead of a
1413 value.
1414
1415 \sa QKeyValueIterator
1416*/
1417
1418/*! \fn template <class Key, class T> QDataStream &operator<<(QDataStream &out, const QMap<Key, T> &map)
1419 \relates QMap
1420
1421 Writes the map \a map to stream \a out.
1422
1423 This function requires the key and value types to implement \c
1424 operator<<().
1425
1426 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1427*/
1428
1429/*! \fn template <class Key, class T> QDataStream &operator>>(QDataStream &in, QMap<Key, T> &map)
1430 \relates QMap
1431
1432 Reads a map from stream \a in into \a map.
1433
1434 This function requires the key and value types to implement \c
1435 operator>>().
1436
1437 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1438*/
1439
1440/*! \fn template <typename Key, typename T, typename Predicate> qsizetype erase_if(QMap<Key, T> &map, Predicate pred)
1441 \relates QMap
1442 \since 6.1
1443
1444 Removes all elements for which the predicate \a pred returns true
1445 from the map \a map.
1446
1447 The function supports predicates which take either an argument of
1448 type \c{QMap<Key, T>::iterator}, or an argument of type
1449 \c{std::pair<const Key &, T &>}.
1450
1451 Returns the number of elements removed, if any.
1452*/
1453
1454/*!
1455 \fn template <class Key, class T> size_t QMap<Key, T>::qHash(const QMap &key, size_t seed) noexcept
1456 \since 6.8
1457 \qhashTS{QMap}{Key}{T}
1458*/