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 Inserting a key/value pair with an existing key replaces the existing
795 value.
796
797 Returns an iterator pointing to the new/updated element.
798*/
799
800/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::insert(const_iterator pos, const Key &key, const T &value)
801 \overload
802 \since 5.1
803 Inserts a new item with the key \a key and value \a value and with hint \a pos
804 suggesting where to do the insert.
805
806 If constBegin() is used as hint it indicates that the \a key is less than any key in the map
807 while constEnd() suggests that the \a key is (strictly) larger than any key in the map.
808 Otherwise the hint should meet the condition (\a pos - 1).key() < \a key <= pos.key().
809 If the hint \a pos is wrong it is ignored and a regular insert is done.
810
811 If there is already an item with the key \a key, that item's value
812 is replaced with \a value.
813
814 If the hint is correct and the map is unshared, the insert executes in amortized \l{constant time}.
815
816 When creating a map from sorted data inserting the largest key first with constBegin()
817 is faster than inserting in sorted order with constEnd(), since constEnd() - 1 (which is needed
818 to check if the hint is valid) needs \l{logarithmic time}.
819
820 \b {Note:} Be careful with the hint. Providing an iterator from an older shared instance might
821 crash but there is also a risk that it will silently corrupt both the map and the \a pos map.
822
823 Returns an iterator pointing to the new/updated element.
824*/
825
826/*! \fn template <class Key, class T> void QMap<Key, T>::insert(const QMap<Key, T> &map)
827 \since 5.15
828
829 Inserts all the items in \a map into this map.
830
831 If a key is common to both maps, its value will be replaced with
832 the value stored in \a map.
833*/
834
835/*! \fn template <class Key, class T> void QMap<Key, T>::insert(QMap<Key, T> &&map)
836 \since 5.15
837
838 Moves all the items from \a map into this map.
839
840 If a key is common to both maps, its value will be replaced with
841 the value stored in \a map.
842
843 If \a map is shared, then the items will be copied instead.
844*/
845
846/*! \typedef QMap::Iterator
847
848 Qt-style synonym for QMap::iterator.
849*/
850
851/*! \typedef QMap::ConstIterator
852
853 Qt-style synonym for QMap::const_iterator.
854*/
855
856/*! \typedef QMap::difference_type
857
858 Typedef for ptrdiff_t. Provided for STL compatibility.
859*/
860
861/*! \typedef QMap::key_type
862
863 Typedef for Key. Provided for STL compatibility.
864*/
865
866/*! \typedef QMap::mapped_type
867
868 Typedef for T. Provided for STL compatibility.
869*/
870
871/*! \typedef QMap::size_type
872
873 Typedef for int. Provided for STL compatibility.
874*/
875
876/*!
877 \fn template <class Key, class T> bool QMap<Key, T>::empty() const
878
879 This function is provided for STL compatibility. It is equivalent
880 to isEmpty(), returning true if the map is empty; otherwise
881 returning false.
882*/
883
884/*!
885 \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)
886
887 Returns a pair of iterators delimiting the range of values \c{[first, second)}, that
888 are stored under \a key.
889*/
890
891/*!
892 \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
893 \overload
894 \since 5.6
895*/
896
897
898/*! \class QMap::iterator
899 \inmodule QtCore
900 \brief The QMap::iterator class provides an STL-style non-const iterator for QMap.
901
902 QMap<Key, T>::iterator allows you to iterate over a QMap
903 and to modify the value (but not the key) stored under
904 a particular key. If you want to iterate over a const QMap, you
905 should use QMap::const_iterator. It is generally good practice to
906 use QMap::const_iterator on a non-const QMap as well, unless you
907 need to change the QMap through the iterator. Const iterators are
908 slightly faster, and can improve code readability.
909
910 The default QMap::iterator constructor creates an uninitialized
911 iterator. You must initialize it using a QMap function like
912 QMap::begin(), QMap::end(), or QMap::find() before you can
913 start iterating. Here's a typical loop that prints all the (key,
914 value) pairs stored in a map:
915
916 \snippet code/src_corelib_tools_qmap.cpp 18
917
918 Unlike QHash, which stores its items in an arbitrary order, QMap
919 stores its items ordered by key.
920
921 Here's an example that increments every value stored in the QMap
922 by 2:
923
924 \snippet code/src_corelib_tools_qmap.cpp 19
925
926 To remove elements from a QMap you can use erase_if(QMap<Key, T> &map, Predicate pred):
927
928 \snippet code/src_corelib_tools_qmap.cpp 21
929
930 Multiple iterators can be used on the same map. If you add items
931 to the map, existing iterators will remain valid. If you remove
932 items from the map, iterators that point to the removed items
933 will become dangling iterators.
934
935 \warning Iterators on implicitly shared containers do not work
936 exactly like STL-iterators. You should avoid copying a container
937 while iterators are active on that container. For more information,
938 read \l{Implicit sharing iterator problem}.
939
940 \sa QMap::const_iterator, QMap::key_iterator, QMap::key_value_iterator
941*/
942
943/*! \typedef QMap::iterator::difference_type
944
945 \internal
946*/
947
948/*! \typedef QMap::iterator::iterator_category
949
950 A synonym for \e {std::bidirectional_iterator_tag} indicating
951 this iterator is a bidirectional iterator.
952*/
953
954/*! \typedef QMap::iterator::pointer
955
956 \internal
957*/
958
959/*! \typedef QMap::iterator::reference
960
961 \internal
962*/
963
964/*! \typedef QMap::iterator::value_type
965
966 \internal
967*/
968
969/*! \fn template <class Key, class T> QMap<Key, T>::iterator::iterator()
970
971 Constructs an uninitialized iterator.
972
973 Functions like key(), value(), and operator++() must not be
974 called on an uninitialized iterator. Use operator=() to assign a
975 value to it before using it.
976
977 \sa QMap::begin(), QMap::end()
978*/
979
980/*! \fn template <class Key, class T> const Key &QMap<Key, T>::iterator::key() const
981
982 Returns the current item's key as a const reference.
983
984 There is no direct way of changing an item's key through an
985 iterator, although it can be done by calling QMap::erase()
986 followed by QMap::insert().
987
988 \sa value()
989*/
990
991/*! \fn template <class Key, class T> T &QMap<Key, T>::iterator::value() const
992
993 Returns a modifiable reference to the current item's value.
994
995 You can change the value of an item by using value() on
996 the left side of an assignment, for example:
997
998 \snippet code/src_corelib_tools_qmap.cpp 23
999
1000 \sa key(), operator*()
1001*/
1002
1003/*! \fn template <class Key, class T> T &QMap<Key, T>::iterator::operator*() const
1004
1005 Returns a modifiable reference to the current item's value.
1006
1007 Same as value().
1008
1009 \sa key()
1010*/
1011
1012/*! \fn template <class Key, class T> T *QMap<Key, T>::iterator::operator->() const
1013
1014 Returns a pointer to the current item's value.
1015
1016 \sa value()
1017*/
1018
1019/*!
1020 \fn template <class Key, class T> bool QMap<Key, T>::iterator::operator==(const iterator &lhs, const iterator &rhs)
1021 \fn template <class Key, class T> bool QMap<Key, T>::const_iterator::operator==(const const_iterator &lhs, const const_iterator &rhs)
1022
1023 Returns \c true if \a lhs points to the same item as the \a rhs iterator;
1024 otherwise returns \c false.
1025
1026 \sa operator!=()
1027*/
1028
1029/*!
1030 \fn template <class Key, class T> bool QMap<Key, T>::iterator::operator!=(const iterator &lhs, const iterator &rhs)
1031 \fn template <class Key, class T> bool QMap<Key, T>::const_iterator::operator!=(const const_iterator &lhs, const const_iterator &rhs)
1032
1033 Returns \c true if \a lhs points to a different item than the \a rhs iterator;
1034 otherwise returns \c false.
1035
1036 \sa operator==()
1037*/
1038
1039/*! \fn template <class Key, class T> QMap<Key, T>::iterator &QMap<Key, T>::iterator::operator++()
1040
1041 The prefix \c{++} operator (\c{++i}) advances the iterator to the
1042 next item in the map and returns an iterator to the new current
1043 item.
1044
1045 Calling this function on QMap::end() leads to undefined results.
1046
1047 \sa operator--()
1048*/
1049
1050/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::iterator::operator++(int)
1051
1052 \overload
1053
1054 The postfix \c{++} operator (\c{i++}) advances the iterator to the
1055 next item in the map and returns an iterator to the previously
1056 current item.
1057*/
1058
1059/*! \fn template <class Key, class T> QMap<Key, T>::iterator &QMap<Key, T>::iterator::operator--()
1060
1061 The prefix \c{--} operator (\c{--i}) makes the preceding item
1062 current and returns an iterator pointing to the new current item.
1063
1064 Calling this function on QMap::begin() leads to undefined
1065 results.
1066
1067 \sa operator++()
1068*/
1069
1070/*! \fn template <class Key, class T> QMap<Key, T>::iterator QMap<Key, T>::iterator::operator--(int)
1071
1072 \overload
1073
1074 The postfix \c{--} operator (\c{i--}) makes the preceding item
1075 current and returns an iterator pointing to the previously
1076 current item.
1077*/
1078
1079/*! //! friends
1080 \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)
1081 \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)
1082 \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)
1083 \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)
1084
1085 //! members
1086 \fn template <class Key, class T> typename QMap<Key, T>::iterator QMap<Key, T>::iterator::operator+=(QMap<Key, T>::iterator::difference_type n)
1087 \fn template <class Key, class T> typename QMap<Key, T>::iterator QMap<Key, T>::iterator::operator-=(QMap<Key, T>::iterator::difference_type n)
1088
1089 \deprecated [6.2] Use \c{std::next}, \c{std::prev} or \c{std::advance} instead.
1090
1091 Moves an iterator by \e{n} positions. These operations can be
1092 expensive for large values of \e{n}; QMap iterators are not
1093 random access.
1094*/
1095
1096/*! \class QMap::const_iterator
1097 \inmodule QtCore
1098 \brief The QMap::const_iterator class provides an STL-style const iterator for QMap.
1099
1100 QMap<Key, T>::const_iterator allows you to iterate over a QMap.
1101 If you want to modify the QMap as you iterate
1102 over it, you must use QMap::iterator instead. It is generally
1103 good practice to use QMap::const_iterator on a non-const QMap as
1104 well, unless you need to change the QMap through the iterator.
1105 Const iterators are slightly faster, and can improve code
1106 readability.
1107
1108 The default QMap::const_iterator constructor creates an
1109 uninitialized iterator. You must initialize it using a QMap
1110 function like QMap::cbegin(), QMap::cend(), or
1111 QMap::constFind() before you can start iterating. Here's a typical
1112 loop that prints all the (key, value) pairs stored in a map:
1113
1114 \snippet code/src_corelib_tools_qmap.cpp 24
1115
1116 Here's an example that removes all the items whose value is greater than 10:
1117
1118 \snippet code/src_corelib_tools_qmap.cpp 20
1119
1120 And here the same behavior with erase_if()
1121
1122 \snippet code/src_corelib_tools_qmap.cpp 21
1123
1124 Unlike QHash, which stores its items in an arbitrary order, QMap
1125 stores its items ordered by key.
1126
1127 Multiple iterators can be used on the same map. If you add items
1128 to the map, existing iterators will remain valid. If you remove
1129 items from the map, iterators that point to the removed items
1130 will become dangling iterators.
1131
1132 \warning Iterators on implicitly shared containers do not work
1133 exactly like STL-iterators. You should avoid copying a container
1134 while iterators are active on that container. For more information,
1135 read \l{Implicit sharing iterator problem}.
1136
1137 \sa QMap::iterator, QMap::key_iterator, QMap::const_key_value_iterator
1138*/
1139
1140/*! \typedef QMap::const_iterator::difference_type
1141
1142 \internal
1143*/
1144
1145/*! \typedef QMap::const_iterator::iterator_category
1146
1147 A synonym for \e {std::bidirectional_iterator_tag} indicating
1148 this iterator is a bidirectional iterator.
1149*/
1150
1151/*! \typedef QMap::const_iterator::pointer
1152
1153 \internal
1154*/
1155
1156/*! \typedef QMap::const_iterator::reference
1157
1158 \internal
1159*/
1160
1161/*! \typedef QMap::const_iterator::value_type
1162
1163 \internal
1164*/
1165
1166/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator::const_iterator()
1167
1168 Constructs an uninitialized iterator.
1169
1170 Functions like key(), value(), and operator++() must not be
1171 called on an uninitialized iterator. Use operator=() to assign a
1172 value to it before using it.
1173
1174 \sa QMap::constBegin(), QMap::constEnd()
1175*/
1176
1177/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator::const_iterator(const iterator &other)
1178
1179 Constructs a copy of \a other.
1180*/
1181
1182/*! \fn template <class Key, class T> const Key &QMap<Key, T>::const_iterator::key() const
1183
1184 Returns the current item's key.
1185
1186 \sa value()
1187*/
1188
1189/*! \fn template <class Key, class T> const T &QMap<Key, T>::const_iterator::value() const
1190
1191 Returns the current item's value.
1192
1193 \sa key(), operator*()
1194*/
1195
1196/*! \fn template <class Key, class T> const T &QMap<Key, T>::const_iterator::operator*() const
1197
1198 Returns the current item's value.
1199
1200 Same as value().
1201
1202 \sa key()
1203*/
1204
1205/*! \fn template <class Key, class T> const T *QMap<Key, T>::const_iterator::operator->() const
1206
1207 Returns a pointer to the current item's value.
1208
1209 \sa value()
1210*/
1211
1212/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator &QMap<Key, T>::const_iterator::operator++()
1213
1214 The prefix \c{++} operator (\c{++i}) advances the iterator to the
1215 next item in the map and returns an iterator to the new current
1216 item.
1217
1218 Calling this function on QMap::end() leads to undefined results.
1219
1220 \sa operator--()
1221*/
1222
1223/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::const_iterator::operator++(int)
1224
1225 \overload
1226
1227 The postfix \c{++} operator (\c{i++}) advances the iterator to the
1228 next item in the map and returns an iterator to the previously
1229 current item.
1230*/
1231
1232/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator &QMap<Key, T>::const_iterator::operator--()
1233
1234 The prefix \c{--} operator (\c{--i}) makes the preceding item
1235 current and returns an iterator pointing to the new current item.
1236
1237 Calling this function on QMap::begin() leads to undefined
1238 results.
1239
1240 \sa operator++()
1241*/
1242
1243/*! \fn template <class Key, class T> QMap<Key, T>::const_iterator QMap<Key, T>::const_iterator::operator--(int)
1244
1245 \overload
1246
1247 The postfix \c{--} operator (\c{i--}) makes the preceding item
1248 current and returns an iterator pointing to the previously
1249 current item.
1250*/
1251
1252/*! //! friends
1253 \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)
1254 \fn [qmap-op-step-plus-it-const] template <class Key, class T> QMap<Key, T>::operator+(difference_type n, QMap<Key, T>::const_iterator)
1255 \fn [qmap-op-it-minus-step-const] template <class Key, class T> QMap<Key, T>::operator-(QMap<Key, T>::const_iterator, difference_type n)
1256 \fn [qmap-op-step-minus-it-const] template <class Key, class T> QMap<Key, T>::operator-(difference_type n, QMap<Key, T>::const_iterator)
1257
1258 //! members
1259 \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)
1260 \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)
1261
1262 \deprecated [6.2] Use \c{std::next}, \c{std::prev} or \c{std::advance} instead.
1263
1264 Moves an iterator by \e{n} positions. These operations can be
1265 expensive for large values of \e{n}. QMap iterators are not
1266 random access.
1267*/
1268
1269/*! \class QMap::key_iterator
1270 \inmodule QtCore
1271 \since 5.6
1272 \brief The QMap::key_iterator class provides an STL-style const iterator for QMap keys.
1273
1274 QMap::key_iterator is essentially the same as QMap::const_iterator
1275 with the difference that operator*() and operator->() return a key
1276 instead of a value.
1277
1278 For most uses QMap::iterator and QMap::const_iterator should be used,
1279 you can easily access the key by calling QMap::iterator::key():
1280
1281 \snippet code/src_corelib_tools_qmap.cpp keyiterator1
1282
1283 However, to have interoperability between QMap's keys and STL-style
1284 algorithms we need an iterator that dereferences to a key instead
1285 of a value. With QMap::key_iterator we can apply an algorithm to a
1286 range of keys without having to call QMap::keys(), which is inefficient
1287 as it costs one QMap iteration and memory allocation to create a temporary
1288 QList.
1289
1290 \snippet code/src_corelib_tools_qmap.cpp keyiterator2
1291
1292 QMap::key_iterator is const, it's not possible to modify the key.
1293
1294 The default QMap::key_iterator constructor creates an uninitialized
1295 iterator. You must initialize it using a QMap function like
1296 QMap::keyBegin() or QMap::keyEnd().
1297
1298 \warning Iterators on implicitly shared containers do not work
1299 exactly like STL-iterators. You should avoid copying a container
1300 while iterators are active on that container. For more information,
1301 read \l{Implicit sharing iterator problem}.
1302
1303 \sa QMap::const_iterator, QMap::iterator
1304*/
1305
1306/*! \typedef QMap::key_iterator::difference_type
1307 \internal
1308*/
1309
1310/*! \typedef QMap::key_iterator::iterator_category
1311 \internal
1312*/
1313
1314/*! \typedef QMap::key_iterator::pointer
1315 \internal
1316*/
1317
1318/*! \typedef QMap::key_iterator::reference
1319 \internal
1320*/
1321
1322/*! \typedef QMap::key_iterator::value_type
1323 \internal
1324*/
1325
1326/*! \fn template <class Key, class T> const T &QMap<Key, T>::key_iterator::operator*() const
1327
1328 Returns the current item's key.
1329*/
1330
1331/*! \fn template <class Key, class T> const T *QMap<Key, T>::key_iterator::operator->() const
1332
1333 Returns a pointer to the current item's key.
1334*/
1335
1336/*! \fn template <class Key, class T> bool QMap<Key, T>::key_iterator::operator==(key_iterator other) const
1337
1338 Returns \c true if \a other points to the same item as this
1339 iterator; otherwise returns \c false.
1340
1341 \sa operator!=()
1342*/
1343
1344/*! \fn template <class Key, class T> bool QMap<Key, T>::key_iterator::operator!=(key_iterator other) const
1345
1346 Returns \c true if \a other points to a different item than this
1347 iterator; otherwise returns \c false.
1348
1349 \sa operator==()
1350*/
1351
1352/*!
1353 \fn template <class Key, class T> QMap<Key, T>::key_iterator &QMap<Key, T>::key_iterator::operator++()
1354
1355 The prefix \c{++} operator (\c{++i}) advances the iterator to the
1356 next item in the hash and returns an iterator to the new current
1357 item.
1358
1359 Calling this function on QMap::keyEnd() leads to undefined results.
1360
1361 \sa operator--()
1362*/
1363
1364/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator QMap<Key, T>::key_iterator::operator++(int)
1365
1366 \overload
1367
1368 The postfix \c{++} operator (\c{i++}) advances the iterator to the
1369 next item in the hash and returns an iterator to the previous
1370 item.
1371*/
1372
1373/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator &QMap<Key, T>::key_iterator::operator--()
1374
1375 The prefix \c{--} operator (\c{--i}) makes the preceding item
1376 current and returns an iterator pointing to the new current item.
1377
1378 Calling this function on QMap::keyBegin() leads to undefined
1379 results.
1380
1381 \sa operator++()
1382*/
1383
1384/*! \fn template <class Key, class T> QMap<Key, T>::key_iterator QMap<Key, T>::key_iterator::operator--(int)
1385
1386 \overload
1387
1388 The postfix \c{--} operator (\c{i--}) makes the preceding item
1389 current and returns an iterator pointing to the previous
1390 item.
1391*/
1392
1393/*! \fn template <class Key, class T> const_iterator QMap<Key, T>::key_iterator::base() const
1394 Returns the underlying const_iterator this key_iterator is based on.
1395*/
1396
1397/*! \typedef QMap::const_key_value_iterator
1398 \inmodule QtCore
1399 \since 5.10
1400 \brief The QMap::const_key_value_iterator typedef provides an STL-style iterator for QMap.
1401
1402 QMap::const_key_value_iterator is essentially the same as QMap::const_iterator
1403 with the difference that operator*() returns a key/value pair instead of a
1404 value.
1405
1406 \sa QKeyValueIterator
1407*/
1408
1409/*! \typedef QMap::key_value_iterator
1410 \inmodule QtCore
1411 \since 5.10
1412 \brief The QMap::key_value_iterator typedef provides an STL-style iterator for QMap.
1413
1414 QMap::key_value_iterator is essentially the same as QMap::iterator
1415 with the difference that operator*() returns a key/value pair instead of a
1416 value.
1417
1418 \sa QKeyValueIterator
1419*/
1420
1421/*! \fn template <class Key, class T> QDataStream &operator<<(QDataStream &out, const QMap<Key, T> &map)
1422 \relates QMap
1423
1424 Writes the map \a map to stream \a out.
1425
1426 This function requires the key and value types to implement \c
1427 operator<<().
1428
1429 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1430*/
1431
1432/*! \fn template <class Key, class T> QDataStream &operator>>(QDataStream &in, QMap<Key, T> &map)
1433 \relates QMap
1434
1435 Reads a map from stream \a in into \a map.
1436
1437 This function requires the key and value types to implement \c
1438 operator>>().
1439
1440 \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
1441*/
1442
1443/*! \fn template <typename Key, typename T, typename Predicate> qsizetype erase_if(QMap<Key, T> &map, Predicate pred)
1444 \relates QMap
1445 \since 6.1
1446
1447 Removes all elements for which the predicate \a pred returns true
1448 from the map \a map.
1449
1450 The function supports predicates which take either an argument of
1451 type \c{QMap<Key, T>::iterator}, or an argument of type
1452 \c{std::pair<const Key &, T &>}.
1453
1454 Returns the number of elements removed, if any.
1455*/
1456
1457/*!
1458 \fn template <class Key, class T> size_t QMap<Key, T>::qHash(const QMap &key, size_t seed) noexcept
1459 \since 6.8
1460 \qhashTS{QMap}{Key}{T}
1461*/