summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlist.cpp
blob: 8ed0da7ca0e9e298ee1a0b61cf5c60fae91508db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2015 Intel Corporation.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include <new>
#include "qlist.h"
#include "qtools_p.h"

#include <string.h>
#include <stdlib.h>

QT_BEGIN_NAMESPACE

/*
    QList as an array-list combines the easy-of-use of a random
    access interface with fast list operations and the low memory
    management overhead of an array. Accessing elements by index,
    appending, prepending, and removing elements from both the front
    and the back all happen in constant time O(1). Inserting or
    removing elements at random index positions \ai happens in linear
    time, or more precisly in O(min{i,n-i}) <= O(n/2), with n being
    the number of elements in the list.
*/

const QListData::Data QListData::shared_null = { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, { 0 } };

static int grow(int size)
{
    if (size_t(size) > (MaxAllocSize - QListData::DataHeaderSize) / sizeof(void *))
        qBadAlloc();
    // dear compiler: don't optimize me out.
    volatile int x = qAllocMore(size * sizeof(void *), QListData::DataHeaderSize) / sizeof(void *);
    return x;
}

/*!
 *  Detaches the QListData by allocating new memory for a list which will be bigger
 *  than the copied one and is expected to grow further.
 *  *idx is the desired insertion point and is clamped to the actual size of the list.
 *  num is the number of new elements to insert at the insertion point.
 *  Returns the old (shared) data, it is up to the caller to deref() and free().
 *  For the new data node_copy needs to be called.
 *
 *  \internal
 */
QListData::Data *QListData::detach_grow(int *idx, int num)
{
    Data *x = d;
    int l = x->end - x->begin;
    int nl = l + num;
    int alloc = grow(nl);
    Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *)));
    Q_CHECK_PTR(t);

    t->ref.initializeOwned();
    t->alloc = alloc;
    // The space reservation algorithm's optimization is biased towards appending:
    // Something which looks like an append will put the data at the beginning,
    // while something which looks like a prepend will put it in the middle
    // instead of at the end. That's based on the assumption that prepending
    // is uncommon and even an initial prepend will eventually be followed by
    // at least some appends.
    int bg;
    if (*idx < 0) {
        *idx = 0;
        bg = (alloc - nl) >> 1;
    } else if (*idx > l) {
        *idx = l;
        bg = 0;
    } else if (*idx < (l >> 1)) {
        bg = (alloc - nl) >> 1;
    } else {
        bg = 0;
    }
    t->begin = bg;
    t->end = bg + nl;
    d = t;

    return x;
}

/*!
 *  Detaches the QListData by allocating new memory for a list which possibly
 *  has a different size than the copied one.
 *  Returns the old (shared) data, it is up to the caller to deref() and free()
 *  For the new data node_copy needs to be called.
 *
 *  \internal
 */
QListData::Data *QListData::detach(int alloc)
{
    Data *x = d;
    Data* t = static_cast<Data *>(::malloc(DataHeaderSize + alloc * sizeof(void *)));
    Q_CHECK_PTR(t);

    t->ref.initializeOwned();
    t->alloc = alloc;
    if (!alloc) {
        t->begin = 0;
        t->end = 0;
    } else {
        t->begin = x->begin;
        t->end   = x->end;
    }
    d = t;

    return x;
}

void QListData::realloc(int alloc)
{
    Q_ASSERT(!d->ref.isShared());
    Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *)));
    Q_CHECK_PTR(x);

    d = x;
    d->alloc = alloc;
    if (!alloc)
        d->begin = d->end = 0;
}

void QListData::realloc_grow(int growth)
{
    Q_ASSERT(!d->ref.isShared());
    int alloc = grow(d->alloc + growth);
    Data *x = static_cast<Data *>(::realloc(d, DataHeaderSize + alloc * sizeof(void *)));
    Q_CHECK_PTR(x);

    d = x;
    d->alloc = alloc;
}

void QListData::dispose(Data *d)
{
    Q_ASSERT(!d->ref.isShared());
    free(d);
}

// ensures that enough space is available to append n elements
void **QListData::append(int n)
{
    Q_ASSERT(!d->ref.isShared());
    int e = d->end;
    if (e + n > d->alloc) {
        int b = d->begin;
        if (b - n >= 2 * d->alloc / 3) {
            // we have enough space. Just not at the end -> move it.
            e -= b;
            ::memcpy(d->array, d->array + b, e * sizeof(void *));
            d->begin = 0;
        } else {
            realloc_grow(n);
        }
    }
    d->end = e + n;
    return d->array + e;
}

// ensures that enough space is available to append one element
void **QListData::append()
{
    return append(1);
}

// ensures that enough space is available to append the list
void **QListData::append(const QListData& l)
{
    return append(l.d->end - l.d->begin);
}

void **QListData::prepend()
{
    Q_ASSERT(!d->ref.isShared());
    if (d->begin == 0) {
        if (d->end >= d->alloc / 3)
            realloc_grow(1);

        if (d->end < d->alloc / 3)
            d->begin = d->alloc - 2 * d->end;
        else
            d->begin = d->alloc - d->end;

        ::memmove(d->array + d->begin, d->array, d->end * sizeof(void *));
        d->end += d->begin;
    }
    return d->array + --d->begin;
}

void **QListData::insert(int i)
{
    Q_ASSERT(!d->ref.isShared());
    if (i <= 0)
        return prepend();
    int size = d->end - d->begin;
    if (i >= size)
        return append();

    bool leftward = false;

    if (d->begin == 0) {
        if (d->end == d->alloc) {
            // If the array is full, we expand it and move some items rightward
            realloc_grow(1);
        } else {
            // If there is free space at the end of the array, we move some items rightward
        }
    } else {
        if (d->end == d->alloc) {
            // If there is free space at the beginning of the array, we move some items leftward
            leftward = true;
        } else {
            // If there is free space at both ends, we move as few items as possible
            leftward = (i < size - i);
        }
    }

    if (leftward) {
        --d->begin;
        ::memmove(d->array + d->begin, d->array + d->begin + 1, i * sizeof(void *));
    } else {
        ::memmove(d->array + d->begin + i + 1, d->array + d->begin + i,
                  (size - i) * sizeof(void *));
        ++d->end;
    }
    return d->array + d->begin + i;
}

void QListData::remove(int i)
{
    Q_ASSERT(!d->ref.isShared());
    i += d->begin;
    if (i - d->begin < d->end - i) {
        if (int offset = i - d->begin)
            ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));
        d->begin++;
    } else {
        if (int offset = d->end - i - 1)
            ::memmove(d->array + i, d->array + i + 1, offset * sizeof(void *));
        d->end--;
    }
}

void QListData::remove(int i, int n)
{
    Q_ASSERT(!d->ref.isShared());
    i += d->begin;
    int middle = i + n/2;
    if (middle - d->begin < d->end - middle) {
        ::memmove(d->array + d->begin + n, d->array + d->begin,
                   (i - d->begin) * sizeof(void*));
        d->begin += n;
    } else {
        ::memmove(d->array + i, d->array + i + n,
                   (d->end - i - n) * sizeof(void*));
        d->end -= n;
    }
}

void QListData::move(int from, int to)
{
    Q_ASSERT(!d->ref.isShared());
    if (from == to)
        return;

    from += d->begin;
    to += d->begin;
    void *t = d->array[from];

    if (from < to) {
        if (d->end == d->alloc || 3 * (to - from) < 2 * (d->end - d->begin)) {
            ::memmove(d->array + from, d->array + from + 1, (to - from) * sizeof(void *));
        } else {
            // optimization
            if (int offset = from - d->begin)
                ::memmove(d->array + d->begin + 1, d->array + d->begin, offset * sizeof(void *));
            if (int offset = d->end - (to + 1))
                ::memmove(d->array + to + 2, d->array + to + 1, offset * sizeof(void *));
            ++d->begin;
            ++d->end;
            ++to;
        }
    } else {
        if (d->begin == 0 || 3 * (from - to) < 2 * (d->end - d->begin)) {
            ::memmove(d->array + to + 1, d->array + to, (from - to) * sizeof(void *));
        } else {
            // optimization
            if (int offset = to - d->begin)
                ::memmove(d->array + d->begin - 1, d->array + d->begin, offset * sizeof(void *));
            if (int offset = d->end - (from + 1))
                ::memmove(d->array + from, d->array + from + 1, offset * sizeof(void *));
            --d->begin;
            --d->end;
            --to;
        }
    }
    d->array[to] = t;
}

void **QListData::erase(void **xi)
{
    Q_ASSERT(!d->ref.isShared());
    int i = xi - (d->array + d->begin);
    remove(i);
    return d->array + d->begin + i;
}

/*! \class QList
    \inmodule QtCore
    \brief The QList class is a template class that provides lists.

    \ingroup tools
    \ingroup shared

    \reentrant

    QList\<T\> is one of Qt's generic \l{container classes}. It
    stores items in a list that provides fast index-based access
    and index-based insertions and removals.

    QList\<T\>, QLinkedList\<T\>, and QVector\<T\> provide similar
    APIs and functionality. They are often interchangeable, but there
    are performance consequences. Here is an overview of use cases:

    \list
    \li QVector should be your default first choice.
        QVector\<T\> will usually give better performance than QList\<T\>,
        because QVector\<T\> always stores its items sequentially in memory,
        where QList\<T\> will allocate its items on the heap unless
        \c {sizeof(T) <= sizeof(void*)} and T has been declared to be
        either a \c{Q_MOVABLE_TYPE} or a \c{Q_PRIMITIVE_TYPE} using
        \l {Q_DECLARE_TYPEINFO}. See the \l {Pros and Cons of Using QList}
        for an explanation.
    \li However, QList is used throughout the Qt APIs for passing
        parameters and for returning values. Use QList to interface with
        those APIs.
    \li If you need a real linked list, which guarantees
        \l {Algorithmic Complexity}{constant time} insertions mid-list and
        uses iterators to items rather than indexes, use QLinkedList.
    \endlist

    \note QVector and QVarLengthArray both guarantee C-compatible
    array layout. QList does not. This might be important if your
    application must interface with a C API.

    \note Iterators into a QLinkedList and references into
    heap-allocating QLists remain valid long as the referenced items
    remain in the container. This is not true for iterators and
    references into a QVector and non-heap-allocating QLists.

    Internally, QList\<T\> is represented as an array of T if
    \c{sizeof(T) <= sizeof(void*)} and T has been declared to be
    either a \c{Q_MOVABLE_TYPE} or a \c{Q_PRIMITIVE_TYPE} using
    \l {Q_DECLARE_TYPEINFO}. Otherwise, QList\<T\> is represented
    as an array of T* and the items are allocated on the heap.

    The array representation allows very fast insertions and
    index-based access. The prepend() and append() operations are
    also very fast because QList preallocates memory at both
    ends of its internal array. (See \l{Algorithmic Complexity} for
    details.

    Note, however, that when the conditions specified above are not met,
    each append or insert of a new item requires allocating the new item
    on the heap, and this per item allocation will make QVector a better
    choice for use cases that do a lot of appending or inserting, because
    QVector can allocate memory for many items in a single heap allocation.

    Note that the internal array only ever gets bigger over the life
    of the list. It never shrinks. The internal array is deallocated
    by the destructor and by the assignment operator, when one list
    is assigned to another.

    Here's an example of a QList that stores integers and
    a QList that stores QDate values:

    \snippet code/src_corelib_tools_qlistdata.cpp 0

    Qt includes a QStringList class that inherits QList\<QString\>
    and adds a few convenience functions, such as QStringList::join()
    and QStringList::filter().  QString::split() creates QStringLists
    from strings.

    QList stores a list of items. The default constructor creates an
    empty list. To insert items into the list, you can use
    operator<<():

    \snippet code/src_corelib_tools_qlistdata.cpp 1

    QList provides these basic functions to add, move, and remove
    items: insert(), replace(), removeAt(), move(), and swap(). In
    addition, it provides the following convenience functions:
    append(), prepend(), removeFirst(), and removeLast().

    QList uses 0-based indexes, just like C++ arrays. To access the
    item at a particular index position, you can use operator[](). On
    non-const lists, operator[]() returns a reference to the item and
    can be used on the left side of an assignment:

    \snippet code/src_corelib_tools_qlistdata.cpp 2

    Because QList is implemented as an array of pointers for types
    that are larger than a pointer or are not movable, this operation
    requires (\l{Algorithmic Complexity}{constant time}). For read-only
    access, an alternative syntax is to use at():

    \snippet code/src_corelib_tools_qlistdata.cpp 3

    at() can be faster than operator[](), because it never causes a
    \l{deep copy} to occur.

    A common requirement is to remove an item from a list and do
    something with it. For this, QList provides takeAt(), takeFirst(),
    and takeLast(). Here's a loop that removes the items from a list
    one at a time and calls \c delete on them:

    \snippet code/src_corelib_tools_qlistdata.cpp 4

    Inserting and removing items at either end of the list is very
    fast (\l{Algorithmic Complexity}{constant time} in most cases),
    because QList preallocates extra space on both sides of its
    internal buffer to allow for fast growth at both ends of the list.

    If you want to find all occurrences of a particular value in a
    list, use indexOf() or lastIndexOf(). The former searches forward
    starting from a given index position, the latter searches
    backward. Both return the index of a matching item if they find
    it; otherwise, they return -1. For example:

    \snippet code/src_corelib_tools_qlistdata.cpp 5

    If you simply want to check whether a list contains a particular
    value, use contains(). If you want to find out how many times a
    particular value occurs in the list, use count(). If you want to
    replace all occurrences of a particular value with another, use
    replace().

    QList's value type must be an \l{assignable data type}. This
    covers most data types that are commonly used, but the compiler
    won't let you, for example, store a QWidget as a value; instead,
    store a QWidget *. A few functions have additional requirements;
    for example, indexOf() and lastIndexOf() expect the value type to
    support \c operator==().  These requirements are documented on a
    per-function basis.

    Like the other container classes, QList provides \l{Java-style
    iterators} (QListIterator and QMutableListIterator) and
    \l{STL-style iterators} (QList::const_iterator and
    QList::iterator). In practice, these are rarely used, because you
    can use indexes into the QList. QList is implemented in such a way
    that direct index-based access is just as fast as using iterators.

    QList does \e not support inserting, prepending, appending or
    replacing with references to its own values. Doing so will cause
    your application to abort with an error message.

    To make QList as efficient as possible, its member functions don't
    validate their input before using it. Except for isEmpty(), member
    functions always assume the list is \e not empty. Member functions
    that take index values as parameters always assume their index
    value parameters are in the valid range. This means QList member
    functions can fail. If you define QT_NO_DEBUG when you compile,
    failures will not be detected. If you \e don't define QT_NO_DEBUG,
    failures will be detected using Q_ASSERT() or Q_ASSERT_X() with an
    appropriate message.

    To avoid failures when your list can be empty, call isEmpty()
    before calling other member functions. If you must pass an index
    value that might not be in the valid range, check that it is less
    than the value returned by size() but \e not less than 0.

    \section1 More Members

    If T is a QByteArray, this class has a couple more members that can be
    used. See the documentation for QByteArrayList for more information.

    If T is QString, this class has the following additional members:
    \l{QStringList::filter()}{filter},
    \l{QStringList::join()}{join},
    \l{QStringList::removeDuplicates()}{removeDuplicates},
    \l{QStringList::sort()}{sort}.

    \section1 More Information on Using Qt Containers

    For a detailed discussion comparing Qt containers with each other and
    with STL containers, see \l {Understand the Qt Containers}.

    \sa QListIterator, QMutableListIterator, QLinkedList, QVector
*/

/*!
    \fn QList::QList(QList<T> &&other)

    Move-constructs a QList instance, making it point at the same
    object that \a other was pointing to.

    \since 5.2
*/

/*!
    \fn QList<T> QList<T>::mid(int pos, int length) const

    Returns a sub-list which includes elements from this list,
    starting at position \a pos. If \a length is -1 (the default), all
    elements from \a pos are included; otherwise \a length elements (or
    all remaining elements if there are less than \a length elements)
    are included.
*/

/*! \fn QList::QList()

    Constructs an empty list.
*/

/*! \fn QList::QList(const QList<T> &other)

    Constructs a copy of \a other.

    This operation takes \l{Algorithmic Complexity}{constant time},
    because QList is \l{implicitly shared}. This makes returning a
    QList from a function very fast. If a shared instance is modified,
    it will be copied (copy-on-write), and that takes
    \l{Algorithmic Complexity}{linear time}.

    \sa operator=()
*/

/*! \fn inline QList::QList(std::initializer_list<T> args)
    \since 4.8

    Construct a list from the std::initializer_list specified by \a args.

    This constructor is only enabled if the compiler supports C++11 initializer
    lists.
*/

/*! \fn QList::~QList()

    Destroys the list. References to the values in the list and all
    iterators of this list become invalid.
*/

/*! \fn QList<T> &QList::operator=(const QList<T> &other)

    Assigns \a other to this list and returns a reference to this
    list.
*/

/*!
    \fn QList &QList::operator=(QList<T> &&other)

    Move-assigns \a other to this QList instance.

    \since 5.2
*/

/*! \fn void QList::swap(QList<T> &other)
    \since 4.8

    Swaps list \a other with this list. This operation is very
    fast and never fails.
*/

/*! \fn bool QList::operator==(const QList<T> &other) const

    Returns \c true if \a other is equal to this list; otherwise returns
    false.

    Two lists are considered equal if they contain the same values in
    the same order.

    This function requires the value type to have an implementation of
    \c operator==().

    \sa operator!=()
*/

/*! \fn bool QList::operator!=(const QList<T> &other) const

    Returns \c true if \a other is not equal to this list; otherwise
    returns \c false.

    Two lists are considered equal if they contain the same values in
    the same order.

    This function requires the value type to have an implementation of
    \c operator==().

    \sa operator==()
*/

/*! \fn bool operator<(const QList<T> &lhs, const QList<T> &rhs)
    \since 5.6
    \relates QList

    Returns \c true if list \a lhs is
    \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
    {lexicographically less than} \a rhs; otherwise returns \c false.

    This function requires the value type to have an implementation
    of \c operator<().
*/

/*! \fn bool operator<=(const QList<T> &lhs, const QList<T> &rhs)
    \since 5.6
    \relates QList

    Returns \c true if list \a lhs is
    \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
    {lexicographically less than or equal to} \a rhs; otherwise returns \c false.

    This function requires the value type to have an implementation
    of \c operator<().
*/

/*! \fn bool operator>(const QList<T> &lhs, const QList<T> &rhs)
    \since 5.6
    \relates QList

    Returns \c true if list \a lhs is
    \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
    {lexicographically greater than} \a rhs; otherwise returns \c false.

    This function requires the value type to have an implementation
    of \c operator<().
*/

/*! \fn bool operator>=(const QList<T> &lhs, const QList<T> &rhs)
    \since 5.6
    \relates QList

    Returns \c true if list \a lhs is
    \l{http://en.cppreference.com/w/cpp/algorithm/lexicographical_compare}
    {lexicographically greater than or equal to} \a rhs; otherwise returns \c false.

    This function requires the value type to have an implementation
    of \c operator<().
*/

/*!
    \fn uint qHash(const QList<T> &key, uint seed = 0)
    \since 5.6
    \relates QList

    Returns the hash value for \a key,
    using \a seed to seed the calculation.

    This function requires qHash() to be overloaded for the value type \c T.
*/

/*!
    \fn int QList::size() const

    Returns the number of items in the list.

    \sa isEmpty(), count()
*/

/*! \fn void QList::detach()

    \internal
*/

/*! \fn void QList::detachShared()

    \internal

    like detach(), but does nothing if we're shared_null.
    This prevents needless mallocs, and makes QList more exception safe
    in case of cleanup work done in destructors on empty lists.
*/

/*! \fn bool QList::isDetached() const

    \internal
*/

/*! \fn void QList::setSharable(bool sharable)

    \internal
*/

/*! \fn bool QList::isSharedWith(const QList<T> &other) const

    \internal
*/

/*! \fn bool QList::isEmpty() const

    Returns \c true if the list contains no items; otherwise returns
    false.

    \sa size()
*/

/*! \fn void QList::clear()

    Removes all items from the list.

    \sa removeAll()
*/

/*! \fn const T &QList::at(int i) const

    Returns the item at index position \a i in the list. \a i must be
    a valid index position in the list (i.e., 0 <= \a i < size()).

    This function is very fast (\l{Algorithmic Complexity}{constant time}).

    \sa value(), operator[]()
*/

/*! \fn T &QList::operator[](int i)

    Returns the item at index position \a i as a modifiable reference.
    \a i must be a valid index position in the list (i.e., 0 <= \a i <
    size()).

    If this function is called on a list that is currently being shared, it
    will trigger a copy of all elements. Otherwise, this function runs in
    \l{Algorithmic Complexity}{constant time}. If you do not want to modify
    the list you should use QList::at().

    \sa at(), value()
*/

/*! \fn const T &QList::operator[](int i) const

    \overload

    Same as at(). This function runs in \l{Algorithmic Complexity}{constant time}.
*/

/*! \fn QList::reserve(int alloc)

    Reserve space for \a alloc elements.

    If \a alloc is smaller than the current size of the list, nothing will happen.

    Use this function to avoid repetetive reallocation of QList's internal
    data if you can predict how many elements will be appended.
    Note that the reservation applies only to the internal pointer array.

    \since 4.7
*/

/*! \fn void QList::append(const T &value)

    Inserts \a value at the end of the list.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 6

    This is the same as list.insert(size(), \a value).

    If this list is not shared, this operation is typically
    very fast (amortized \l{Algorithmic Complexity}{constant time}),
    because QList preallocates extra space on both sides of its
    internal buffer to allow for fast growth at both ends of the list.

    \sa operator<<(), prepend(), insert()
*/

/*! \fn void QList::append(const QList<T> &value)

    \overload

    \since 4.5

    Appends the items of the \a value list to this list.

    \sa operator<<(), operator+=()
*/

/*! \fn void QList::prepend(const T &value)

    Inserts \a value at the beginning of the list.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 7

    This is the same as list.insert(0, \a value).

    If this list is not shared, this operation is typically
    very fast (amortized \l{Algorithmic Complexity}{constant time}),
    because QList preallocates extra space on both sides of its
    internal buffer to allow for fast growth at both ends of the list.

    \sa append(), insert()
*/

/*! \fn void QList::insert(int i, const T &value)

    Inserts \a value at index position \a i in the list. If \a i
    is 0, the value is prepended to the list. If \a i is size(), the
    value is appended to the list.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 8

    \sa append(), prepend(), replace(), removeAt()
*/

/*! \fn QList::iterator QList::insert(iterator before, const T &value)

    \overload

    Inserts \a value in front of the item pointed to by the
    iterator \a before. Returns an iterator pointing at the inserted
    item. Note that the iterator passed to the function will be
    invalid after the call; the returned iterator should be used
    instead.
*/

/*! \fn void QList::replace(int i, const T &value)

    Replaces the item at index position \a i with \a value. \a i must
    be a valid index position in the list (i.e., 0 <= \a i < size()).

    \sa operator[](), removeAt()
*/

/*!
    \fn int QList::removeAll(const T &value)

    Removes all occurrences of \a value in the list and returns the
    number of entries removed.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 9

    This function requires the value type to have an implementation of
    \c operator==().

    \sa removeOne(), removeAt(), takeAt(), replace()
*/

/*!
    \fn bool QList::removeOne(const T &value)
    \since 4.4

    Removes the first occurrence of \a value in the list and returns
    true on success; otherwise returns \c false.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 10

    This function requires the value type to have an implementation of
    \c operator==().

    \sa removeAll(), removeAt(), takeAt(), replace()
*/

/*! \fn void QList::removeAt(int i)

    Removes the item at index position \a i. \a i must be a valid
    index position in the list (i.e., 0 <= \a i < size()).

    \sa takeAt(), removeFirst(), removeLast(), removeOne()
*/

/*! \fn T QList::takeAt(int i)

    Removes the item at index position \a i and returns it. \a i must
    be a valid index position in the list (i.e., 0 <= \a i < size()).

    If you don't use the return value, removeAt() is more efficient.

    \sa removeAt(), takeFirst(), takeLast()
*/

/*! \fn T QList::takeFirst()

    Removes the first item in the list and returns it. This is the
    same as takeAt(0). This function assumes the list is not empty. To
    avoid failure, call isEmpty() before calling this function.

    If this list is not shared, this operation takes
    \l {Algorithmic Complexity}{constant time}.

    If you don't use the return value, removeFirst() is more
    efficient.

    \sa takeLast(), takeAt(), removeFirst()
*/

/*! \fn T QList::takeLast()

    Removes the last item in the list and returns it. This is the
    same as takeAt(size() - 1). This function assumes the list is
    not empty. To avoid failure, call isEmpty() before calling this
    function.

    If this list is not shared, this operation takes
    \l {Algorithmic Complexity}{constant time}.

    If you don't use the return value, removeLast() is more
    efficient.

    \sa takeFirst(), takeAt(), removeLast()
*/

/*! \fn void QList::move(int from, int to)

    Moves the item at index position \a from to index position \a to.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 11

    This is the same as insert(\a{to}, takeAt(\a{from})).This function
    assumes that both \a from and \a to are at least 0 but less than
    size(). To avoid failure, test that both \a from and \a to are at
    least 0 and less than size().

    \sa swap(), insert(), takeAt()
*/

/*! \fn void QList::swap(int i, int j)

    Exchange the item at index position \a i with the item at index
    position \a j. This function assumes that both \a i and \a j are
    at least 0 but less than size(). To avoid failure, test that both
    \a i and \a j are at least 0 and less than size().

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 12

    \sa move()
*/

/*! \fn int QList::indexOf(const T &value, int from = 0) const

    Returns the index position of the first occurrence of \a value in
    the list, searching forward from index position \a from. Returns
    -1 if no item matched.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 13

    This function requires the value type to have an implementation of
    \c operator==().

    Note that QList uses 0-based indexes, just like C++ arrays. Negative
    indexes are not supported with the exception of the value mentioned
    above.

    \sa lastIndexOf(), contains()
*/

/*! \fn int QList::lastIndexOf(const T &value, int from = -1) const

    Returns the index position of the last occurrence of \a value in
    the list, searching backward from index position \a from. If \a
    from is -1 (the default), the search starts at the last item.
    Returns -1 if no item matched.

    Example:
    \snippet code/src_corelib_tools_qlistdata.cpp 14

    This function requires the value type to have an implementation of
    \c operator==().

    Note that QList uses 0-based indexes, just like C++ arrays. Negative
    indexes are not supported with the exception of the value mentioned
    above.

    \sa indexOf()
*/

/*! \fn bool QList::contains(const T &value) const

    Returns \c true if the list contains an occurrence of \a value;
    otherwise returns \c false.

    This function requires the value type to have an implementation of
    \c operator==().

    \sa indexOf(), count()
*/

/*! \fn int QList::count(const T &value) const

    Returns the number of occurrences of \a value in the list.

    This function requires the value type to have an implementation of
    \c operator==().

    \sa contains(), indexOf()
*/

/*! \fn bool QList::startsWith(const T &value) const
    \since 4.5

    Returns \c true if this list is not empty and its first
    item is equal to \a value; otherwise returns \c false.

    \sa isEmpty(), contains()
*/

/*! \fn bool QList::endsWith(const T &value) const
    \since 4.5

    Returns \c true if this list is not empty and its last
    item is equal to \a value; otherwise returns \c false.

    \sa isEmpty(), contains()
*/

/*! \fn QList::iterator QList::begin()

    Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in
    the list.

    \sa constBegin(), end()
*/

/*! \fn QList::const_iterator QList::begin() const

    \overload
*/

/*! \fn QList::const_iterator QList::cbegin() const
    \since 5.0

    Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
    in the list.

    \sa begin(), cend()
*/

/*! \fn QList::const_iterator QList::constBegin() const

    Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item
    in the list.

    \sa begin(), constEnd()
*/

/*! \fn QList::iterator QList::end()

    Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item
    after the last item in the list.

    \sa begin(), constEnd()
*/

/*! \fn const_iterator QList::end() const

    \overload
*/

/*! \fn QList::const_iterator QList::cend() const
    \since 5.0

    Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
    item after the last item in the list.

    \sa cbegin(), end()
*/

/*! \fn QList::const_iterator QList::constEnd() const

    Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary
    item after the last item in the list.

    \sa constBegin(), end()
*/

/*! \fn QList::reverse_iterator QList::rbegin()
    \since 5.6

    Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
    item in the list, in reverse order.

    \sa begin(), crbegin(), rend()
*/

/*! \fn QList::const_reverse_iterator QList::rbegin() const
    \since 5.6
    \overload
*/

/*! \fn QList::const_reverse_iterator QList::crbegin() const
    \since 5.6

    Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to the first
    item in the list, in reverse order.

    \sa begin(), rbegin(), rend()
*/

/*! \fn QList::reverse_iterator QList::rend()
    \since 5.6

    Returns a \l{STL-style iterators}{STL-style} reverse iterator pointing to one past
    the last item in the list, in reverse order.

    \sa end(), crend(), rbegin()
*/

/*! \fn QList::const_reverse_iterator QList::rend() const
    \since 5.6
    \overload
*/

/*! \fn QList::const_reverse_iterator QList::crend() const
    \since 5.6

    Returns a const \l{STL-style iterators}{STL-style} reverse iterator pointing to one
    past the last item in the list, in reverse order.

    \sa end(), rend(), rbegin()
*/

/*! \fn QList::iterator QList::erase(iterator pos)

    Removes the item associated with the iterator \a pos from the
    list, and returns an iterator to the next item in the list (which
    may be end()).

    \sa insert(), removeAt()
*/

/*! \fn QList::iterator QList::erase(iterator begin, iterator end)

    \overload

    Removes all the items from \a begin up to (but not including) \a
    end. Returns an iterator to the same item that \a end referred to
    before the call.
*/

/*! \typedef QList::Iterator

    Qt-style synonym for QList::iterator.
*/

/*! \typedef QList::ConstIterator

    Qt-style synonym for QList::const_iterator.
*/

/*!
    \typedef QList::size_type

    Typedef for int. Provided for STL compatibility.
*/

/*!
    \typedef QList::value_type

    Typedef for T. Provided for STL compatibility.
*/

/*!
    \typedef QList::difference_type

    Typedef for ptrdiff_t. Provided for STL compatibility.
*/

/*!
    \typedef QList::pointer

    Typedef for T *. Provided for STL compatibility.
*/

/*!
    \typedef QList::const_pointer

    Typedef for const T *. Provided for STL compatibility.
*/

/*!
    \typedef QList::reference

    Typedef for T &. Provided for STL compatibility.
*/

/*!
    \typedef QList::const_reference

    Typedef for const T &. Provided for STL compatibility.
*/

/*! \typedef QList::reverse_iterator
    \since 5.6

    The QList::reverse_iterator typedef provides an STL-style non-const
    reverse iterator for QList.

    It is simply a typedef for \c{std::reverse_iterator<iterator>}.

    \warning Iterators on implicitly shared containers do not work
    exactly like STL-iterators. You should avoid copying a container
    while iterators are active on that container. For more information,
    read \l{Implicit sharing iterator problem}.

    \sa QList::rbegin(), QList::rend(), QList::const_reverse_iterator, QList::iterator
*/

/*! \typedef QList::const_reverse_iterator
    \since 5.6

    The QList::const_reverse_iterator typedef provides an STL-style const
    reverse iterator for QList.

    It is simply a typedef for \c{std::reverse_iterator<const_iterator>}.

    \warning Iterators on implicitly shared containers do not work
    exactly like STL-iterators. You should avoid copying a container
    while iterators are active on that container. For more information,
    read \l{Implicit sharing iterator problem}.

    \sa QList::rbegin(), QList::rend(), QList::reverse_iterator, QList::const_iterator
*/

/*! \fn int QList::count() const

    Returns the number of items in the list. This is effectively the
    same as size().
*/

/*! \fn int QList::length() const
    \since 4.5

    This function is identical to count().

    \sa count()
*/

/*! \fn T& QList::first()

    Returns a reference to the first item in the list. The list must
    not be empty. If the list can be empty, call isEmpty() before
    calling this function.

    \sa constFirst(), last(), isEmpty()
*/

/*! \fn const T& QList::first() const

    \overload
*/

/*! \fn const T& QList::constFirst() const
    \since 5.6

    Returns a const reference to the first item in the list. The list must
    not be empty. If the list can be empty, call isEmpty() before
    calling this function.

    \sa constLast(), isEmpty(), first()
*/

/*! \fn T& QList::last()

    Returns a reference to the last item in the list.  The list must
    not be empty. If the list can be empty, call isEmpty() before
    calling this function.

    \sa constLast(), first(), isEmpty()
*/

/*! \fn const T& QList::last() const

    \overload
*/

/*! \fn const T& QList::constLast() const
    \since 5.6

    Returns a reference to the last item in the list. The list must
    not be empty. If the list can be empty, call isEmpty() before
    calling this function.

    \sa constFirst(), isEmpty(), last()
*/

/*! \fn void QList::removeFirst()

    Removes the first item in the list. Calling this function is
    equivalent to calling removeAt(0). The list must not be empty. If
    the list can be empty, call isEmpty() before calling this
    function.

    \sa removeAt(), takeFirst()
*/

/*! \fn void QList::removeLast()

    Removes the last item in the list. Calling this function is
    equivalent to calling removeAt(size() - 1). The list must not be
    empty. If the list can be empty, call isEmpty() before calling
    this function.

    \sa removeAt(), takeLast()
*/

/*! \fn T QList::value(int i) const

    Returns the value at index position \a i in the list.

    If the index \a i is out of bounds, the function returns a
    \l{default-constructed value}. If you are certain that the index
    is going to be within bounds, you can use at() instead, which is
    slightly faster.

    \sa at(), operator[]()
*/

/*! \fn T QList::value(int i, const T &defaultValue) const

    \overload

    If the index \a i is out of bounds, the function returns
    \a defaultValue.
*/

/*! \fn void QList::push_back(const T &value)

    This function is provided for STL compatibility. It is equivalent
    to \l{QList::append()}{append(\a value)}.
*/

/*! \fn void QList::push_front(const T &value)

    This function is provided for STL compatibility. It is equivalent
    to \l{QList::prepend()}{prepend(\a value)}.
*/

/*! \fn T& QList::front()

    This function is provided for STL compatibility. It is equivalent
    to first(). The list must not be empty. If the list can be empty,
    call isEmpty() before calling this function.
*/

/*! \fn const T& QList::front() const

    \overload
*/

/*! \fn T& QList::back()

    This function is provided for STL compatibility. It is equivalent
    to last(). The list must not be empty. If the list can be empty,
    call isEmpty() before calling this function.
*/

/*! \fn const T& QList::back() const

    \overload
*/

/*! \fn void QList::pop_front()

    This function is provided for STL compatibility. It is equivalent
    to removeFirst(). The list must not be empty. If the list can be
    empty, call isEmpty() before calling this function.
*/

/*! \fn void QList::pop_back()

    This function is provided for STL compatibility. It is equivalent
    to removeLast(). The list must not be empty. If the list can be
    empty, call isEmpty() before calling this function.
*/

/*! \fn bool QList::empty() const

    This function is provided for STL compatibility. It is equivalent
    to isEmpty() and returns \c true if the list is empty.
*/

/*! \fn QList<T> &QList::operator+=(const QList<T> &other)

    Appends the items of the \a other list to this list and returns a
    reference to this list.

    \sa operator+(), append()
*/

/*! \fn void QList::operator+=(const T &value)

    \overload

    Appends \a value to the list.

    \sa append(), operator<<()
*/

/*! \fn QList<T> QList::operator+(const QList<T> &other) const

    Returns a list that contains all the items in this list followed
    by all the items in the \a other list.

    \sa operator+=()
*/

/*! \fn QList<T> &QList::operator<<(const QList<T> &other)

    Appends the items of the \a other list to this list and returns a
    reference to this list.

    \sa operator+=(), append()
*/

/*! \fn void QList::operator<<(const T &value)

    \overload

    Appends \a value to the list.
*/

/*! \class QList::iterator
    \inmodule QtCore
    \brief The QList::iterator class provides an STL-style non-const iterator for QList and QQueue.

    QList features both \l{STL-style iterators} and \l{Java-style
    iterators}. The STL-style iterators are more low-level and more
    cumbersome to use; on the other hand, they are slightly faster
    and, for developers who already know STL, have the advantage of
    familiarity.

    QList\<T\>::iterator allows you to iterate over a QList\<T\> (or
    QQueue\<T\>) and to modify the list item associated with the
    iterator. If you want to iterate over a const QList, use
    QList::const_iterator instead. It is generally good practice to
    use QList::const_iterator on a non-const QList as well, unless
    you need to change the QList through the iterator. Const
    iterators are slightly faster, and can improve code readability.

    The default QList::iterator constructor creates an uninitialized
    iterator. You must initialize it using a QList function like
    QList::begin(), QList::end(), or QList::insert() before you can
    start iterating. Here's a typical loop that prints all the items
    stored in a list:

    \snippet code/src_corelib_tools_qlistdata.cpp 15

    Let's see a few examples of things we can do with a
    QList::iterator that we cannot do with a QList::const_iterator.
    Here's an example that increments every value stored in a
    QList\<int\> by 2:

    \snippet code/src_corelib_tools_qlistdata.cpp 16

    Most QList functions accept an integer index rather than an
    iterator. For that reason, iterators are rarely useful in
    connection with QList. One place where STL-style iterators do
    make sense is as arguments to \l{generic algorithms}.

    For example, here's how to delete all the widgets stored in a
    QList\<QWidget *\>:

    \snippet code/src_corelib_tools_qlistdata.cpp 17

    Multiple iterators can be used on the same list. However, be
    aware that any non-const function call performed on the QList
    will render all existing iterators undefined. If you need to keep
    iterators over a long period of time, we recommend that you use
    QLinkedList rather than QList.

    \warning Iterators on implicitly shared containers do not work
    exactly like STL-iterators. You should avoid copying a container
    while iterators are active on that container. For more information,
    read \l{Implicit sharing iterator problem}.

    \sa QList::const_iterator, QMutableListIterator
*/

/*! \typedef QList::iterator::iterator_category

  A synonym for \e {std::random_access_iterator_tag} indicating
  this iterator is a random access iterator.
*/

/*! \typedef QList::iterator::difference_type

    \internal
*/

/*! \typedef QList::iterator::value_type

    \internal
*/

/*! \typedef QList::iterator::pointer

    \internal
*/

/*! \typedef QList::iterator::reference

    \internal
*/

/*! \fn QList::iterator::iterator()

    Constructs an uninitialized iterator.

    Functions like operator*() and operator++() should not be called
    on an uninitialized iterator. Use operator=() to assign a value
    to it before using it.

    \sa QList::begin(), QList::end()
*/

/*! \fn QList::iterator::iterator(Node *node)

    \internal
*/

/*! \fn QList::iterator::iterator(const iterator &other)

    Constructs a copy of \a other.
*/

/*! \fn T &QList::iterator::operator*() const

    Returns a modifiable reference to the current item.

    You can change the value of an item by using operator*() on the
    left side of an assignment, for example:

    \snippet code/src_corelib_tools_qlistdata.cpp 18

    \sa operator->()
*/

/*! \fn T *QList::iterator::operator->() const

    Returns a pointer to the current item.

    \sa operator*()
*/

/*! \fn T &QList::iterator::operator[](difference_type j) const

    Returns a modifiable reference to the item at position *this +
    \a{j}.

    This function is provided to make QList iterators behave like C++
    pointers.

    \sa operator+()
*/

/*!
    \fn bool QList::iterator::operator==(const iterator &other) const
    \fn bool QList::iterator::operator==(const const_iterator &other) const

    Returns \c true if \a other points to the same item as this
    iterator; otherwise returns \c false.

    \sa operator!=()
*/

/*!
    \fn bool QList::iterator::operator!=(const iterator &other) const
    \fn bool QList::iterator::operator!=(const const_iterator &other) const

    Returns \c true if \a other points to a different item than this
    iterator; otherwise returns \c false.

    \sa operator==()
*/

/*!
    \fn bool QList::iterator::operator<(const iterator& other) const
    \fn bool QList::iterator::operator<(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is less than
    the item pointed to by the \a other iterator.
*/

/*!
    \fn bool QList::iterator::operator<=(const iterator& other) const
    \fn bool QList::iterator::operator<=(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is less than
    or equal to the item pointed to by the \a other iterator.
*/

/*!
    \fn bool QList::iterator::operator>(const iterator& other) const
    \fn bool QList::iterator::operator>(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is greater
    than the item pointed to by the \a other iterator.
*/

/*!
    \fn bool QList::iterator::operator>=(const iterator& other) const
    \fn bool QList::iterator::operator>=(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is greater
    than or equal to the item pointed to by the \a other iterator.
*/

/*! \fn QList::iterator &QList::iterator::operator++()

    The prefix ++ operator (\c{++it}) advances the iterator to the
    next item in the list and returns an iterator to the new current
    item.

    Calling this function on QList::end() leads to undefined results.

    \sa operator--()
*/

/*! \fn QList::iterator QList::iterator::operator++(int)

    \overload

    The postfix ++ operator (\c{it++}) advances the iterator to the
    next item in the list and returns an iterator to the previously
    current item.
*/

/*! \fn QList::iterator &QList::iterator::operator--()

    The prefix -- operator (\c{--it}) makes the preceding item
    current and returns an iterator to the new current item.

    Calling this function on QList::begin() leads to undefined results.

    \sa operator++()
*/

/*! \fn QList::iterator QList::iterator::operator--(int)

    \overload

    The postfix -- operator (\c{it--}) makes the preceding item
    current and returns an iterator to the previously current item.
*/

/*! \fn QList::iterator &QList::iterator::operator+=(difference_type j)

    Advances the iterator by \a j items. (If \a j is negative, the
    iterator goes backward.)

    \sa operator-=(), operator+()
*/

/*! \fn QList::iterator &QList::iterator::operator-=(difference_type j)

    Makes the iterator go back by \a j items. (If \a j is negative,
    the iterator goes forward.)

    \sa operator+=(), operator-()
*/

/*! \fn QList::iterator QList::iterator::operator+(difference_type j) const

    Returns an iterator to the item at \a j positions forward from
    this iterator. (If \a j is negative, the iterator goes backward.)

    \sa operator-(), operator+=()
*/

/*! \fn QList::iterator QList::iterator::operator-(difference_type j) const

    Returns an iterator to the item at \a j positions backward from
    this iterator. (If \a j is negative, the iterator goes forward.)

    \sa operator+(), operator-=()
*/

/*! \fn int QList::iterator::operator-(iterator other) const

    Returns the number of items between the item pointed to by \a
    other and the item pointed to by this iterator.
*/

/*! \class QList::const_iterator
    \inmodule QtCore
    \brief The QList::const_iterator class provides an STL-style const iterator for QList and QQueue.

    QList provides both \l{STL-style iterators} and \l{Java-style
    iterators}. The STL-style iterators are more low-level and more
    cumbersome to use; on the other hand, they are slightly faster
    and, for developers who already know STL, have the advantage of
    familiarity.

    QList\<T\>::const_iterator allows you to iterate over a
    QList\<T\> (or a QQueue\<T\>). If you want to modify the QList as
    you iterate over it, use QList::iterator instead. It is generally
    good practice to use QList::const_iterator on a non-const QList
    as well, unless you need to change the QList through the
    iterator. Const iterators are slightly faster, and can improve
    code readability.

    The default QList::const_iterator constructor creates an
    uninitialized iterator. You must initialize it using a QList
    function like QList::constBegin(), QList::constEnd(), or
    QList::insert() before you can start iterating. Here's a typical
    loop that prints all the items stored in a list:

    \snippet code/src_corelib_tools_qlistdata.cpp 19

    Most QList functions accept an integer index rather than an
    iterator. For that reason, iterators are rarely useful in
    connection with QList. One place where STL-style iterators do
    make sense is as arguments to \l{generic algorithms}.

    For example, here's how to delete all the widgets stored in a
    QList\<QWidget *\>:

    \snippet code/src_corelib_tools_qlistdata.cpp 20

    Multiple iterators can be used on the same list. However, be
    aware that any non-const function call performed on the QList
    will render all existing iterators undefined. If you need to keep
    iterators over a long period of time, we recommend that you use
    QLinkedList rather than QList.

    \warning Iterators on implicitly shared containers do not work
    exactly like STL-iterators. You should avoid copying a container
    while iterators are active on that container. For more information,
    read \l{Implicit sharing iterator problem}.

    \sa QList::iterator, QListIterator
*/

/*! \fn QList::const_iterator::const_iterator()

    Constructs an uninitialized iterator.

    Functions like operator*() and operator++() should not be called
    on an uninitialized iterator. Use operator=() to assign a value
    to it before using it.

    \sa QList::constBegin(), QList::constEnd()
*/

/*! \typedef QList::const_iterator::iterator_category

  A synonym for \e {std::random_access_iterator_tag} indicating
  this iterator is a random access iterator.
*/

/*! \typedef QList::const_iterator::difference_type

    \internal
*/

/*! \typedef QList::const_iterator::value_type

    \internal
*/

/*! \typedef QList::const_iterator::pointer

    \internal
*/

/*! \typedef QList::const_iterator::reference

    \internal
*/

/*! \fn QList::const_iterator::const_iterator(Node *node)

    \internal
*/

/*! \fn QList::const_iterator::const_iterator(const const_iterator &other)

    Constructs a copy of \a other.
*/

/*! \fn QList::const_iterator::const_iterator(const iterator &other)

    Constructs a copy of \a other.
*/

/*! \fn const T &QList::const_iterator::operator*() const

    Returns the current item.

    \sa operator->()
*/

/*! \fn const T *QList::const_iterator::operator->() const

    Returns a pointer to the current item.

    \sa operator*()
*/

/*! \fn const T &QList::const_iterator::operator[](difference_type j) const

    Returns the item at position *this + \a{j}.

    This function is provided to make QList iterators behave like C++
    pointers.

    \sa operator+()
*/

/*! \fn bool QList::const_iterator::operator==(const const_iterator &other) const

    Returns \c true if \a other points to the same item as this
    iterator; otherwise returns \c false.

    \sa operator!=()
*/

/*! \fn bool QList::const_iterator::operator!=(const const_iterator &other) const

    Returns \c true if \a other points to a different item than this
    iterator; otherwise returns \c false.

    \sa operator==()
*/

/*!
    \fn bool QList::const_iterator::operator<(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is less than
    the item pointed to by the \a other iterator.
*/

/*!
    \fn bool QList::const_iterator::operator<=(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is less than
    or equal to the item pointed to by the \a other iterator.
*/

/*!
    \fn bool QList::const_iterator::operator>(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is greater
    than the item pointed to by the \a other iterator.
*/

/*!
    \fn bool QList::const_iterator::operator>=(const const_iterator& other) const

    Returns \c true if the item pointed to by this iterator is greater
    than or equal to the item pointed to by the \a other iterator.
*/

/*! \fn QList::const_iterator &QList::const_iterator::operator++()

    The prefix ++ operator (\c{++it}) advances the iterator to the
    next item in the list and returns an iterator to the new current
    item.

    Calling this function on QList::end() leads to undefined results.

    \sa operator--()
*/

/*! \fn QList::const_iterator QList::const_iterator::operator++(int)

    \overload

    The postfix ++ operator (\c{it++}) advances the iterator to the
    next item in the list and returns an iterator to the previously
    current item.
*/

/*! \fn QList::const_iterator &QList::const_iterator::operator--()

    The prefix -- operator (\c{--it}) makes the preceding item
    current and returns an iterator to the new current item.

    Calling this function on QList::begin() leads to undefined results.

    \sa operator++()
*/

/*! \fn QList::const_iterator QList::const_iterator::operator--(int)

    \overload

    The postfix -- operator (\c{it--}) makes the preceding item
    current and returns an iterator to the previously current item.
*/

/*! \fn QList::const_iterator &QList::const_iterator::operator+=(difference_type j)

    Advances the iterator by \a j items. (If \a j is negative, the
    iterator goes backward.)

    \sa operator-=(), operator+()
*/

/*! \fn QList::const_iterator &QList::const_iterator::operator-=(difference_type j)

    Makes the iterator go back by \a j items. (If \a j is negative,
    the iterator goes forward.)

    \sa operator+=(), operator-()
*/

/*! \fn QList::const_iterator QList::const_iterator::operator+(difference_type j) const

    Returns an iterator to the item at \a j positions forward from
    this iterator. (If \a j is negative, the iterator goes backward.)

    \sa operator-(), operator+=()
*/

/*! \fn QList::const_iterator QList::const_iterator::operator-(difference_type j) const

    Returns an iterator to the item at \a j positions backward from
    this iterator. (If \a j is negative, the iterator goes forward.)

    \sa operator+(), operator-=()
*/

/*! \fn int QList::const_iterator::operator-(const_iterator other) const

    Returns the number of items between the item pointed to by \a
    other and the item pointed to by this iterator.
*/

/*! \fn QDataStream &operator<<(QDataStream &out, const QList<T> &list)
    \relates QList

    Writes the list \a list to stream \a out.

    This function requires the value type to implement \c
    operator<<().

    \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
*/

/*! \fn QDataStream &operator>>(QDataStream &in, QList<T> &list)
    \relates QList

    Reads a list from stream \a in into \a list.

    This function requires the value type to implement \c
    operator>>().

    \sa{Serializing Qt Data Types}{Format of the QDataStream operators}
*/

/*! \fn QList<T> QList<T>::fromVector(const QVector<T> &vector)

    Returns a QList object with the data contained in \a vector.

    Example:

    \snippet code/src_corelib_tools_qlistdata.cpp 21

    \sa fromSet(), toVector(), QVector::toList()
*/

/*! \fn QVector<T> QList<T>::toVector() const

    Returns a QVector object with the data contained in this QList.

    Example:

    \snippet code/src_corelib_tools_qlistdata.cpp 22

    \sa toSet(), fromVector(), QVector::fromList()
*/

/*! \fn QList<T> QList<T>::fromSet(const QSet<T> &set)

    Returns a QList object with the data contained in \a set. The
    order of the elements in the QList is undefined.

    Example:

    \snippet code/src_corelib_tools_qlistdata.cpp 23

    \sa fromVector(), toSet(), QSet::toList()
*/

/*! \fn QSet<T> QList<T>::toSet() const

    Returns a QSet object with the data contained in this QList.
    Since QSet doesn't allow duplicates, the resulting QSet might be
    smaller than the original list was.

    Example:

    \snippet code/src_corelib_tools_qlistdata.cpp 24

    \sa toVector(), fromSet(), QSet::fromList()
*/

/*! \fn QList<T> QList<T>::fromStdList(const std::list<T> &list)

    Returns a QList object with the data contained in \a list. The
    order of the elements in the QList is the same as in \a list.

    Example:

    \snippet code/src_corelib_tools_qlistdata.cpp 25

    \sa toStdList(), QVector::fromStdVector()
*/

/*! \fn std::list<T> QList<T>::toStdList() const

    Returns a std::list object with the data contained in this QList.
    Example:

    \snippet code/src_corelib_tools_qlistdata.cpp 26

    \sa fromStdList(), QVector::toStdVector()
*/

QT_END_NAMESPACE