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