qt6-bb10/tests/auto/corelib
Giuseppe D'Angelo 0deff80eab Associative containers: add a way to obtain a key/value range
Our associative containers' iterator's value_type isn't a destructurable
type (yielding key/value). This means that something like

  for (auto [k, v] : map)

doesn't even compile -- one can only "directly" iterate on the
values. For quite some time we've had QKeyValueIterator to allow
key/value iteration, but then one had to resort to a "traditional" for
loop:

  for (auto i = map.keyValueBegin(), e = keyValueEnd(); i!=e; ++i)

This can be easily packaged in an adaptor class, which is what this
commmit does, thereby offering a C++17-compatible way to obtain
key/value iteration over associative containers.

Something possibly peculiar is the fact that the range so obtained is
a range of pairs of references -- not a range of references to pairs.
But that's easily explained by the fact that we have no pairs to build
references to; hence,

 for (auto &[k, v] : map.asKeyValueRange())

doesn't compile (lvalue reference doesn't bind to prvalue pair).
Instead, both of these compile:

  for (auto [k, v] : map.asKeyValueRange())
  for (auto &&[k, v] : map.asKeyValueRange())

and in *both* cases one gets references to the keys/values in the map.
If the map is non-const, the reference to the value is mutable.

Last but not least, implement pinning for rvalue containers.

[ChangeLog][QtCore][QMap] Added asKeyValueRange().
[ChangeLog][QtCore][QMultiMap] Added asKeyValueRange().
[ChangeLog][QtCore][QHash] Added asKeyValueRange().
[ChangeLog][QtCore][QMultiHash] Added asKeyValueRange().

Task-number: QTBUG-4615
Change-Id: Ic8506bff38b2f753494b21ab76f52e05c06ffc8b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2022-03-04 00:21:44 +01:00
..
animation tst_qanimationgroup: fix memleaks 2022-01-05 08:22:00 +01:00
global tst_qflags: don't suppress deprecation warnings 2022-03-03 00:18:39 +01:00
io QSettings: support reading UTF-8 keys in INI files 2022-03-02 11:13:33 +01:00
itemmodels Fix test to pass with QT_FORCE_ASSERTS 2022-02-18 18:55:38 +01:00
kernel QMetaObjectBuilder: Always set Data::metatypes 2022-03-02 10:43:49 +01:00
mimetypes Remove unused .qrc files 2022-01-17 23:17:01 +01:00
platform Android: Add runOnMainAndroidThread() under QNativeInterface 2021-05-26 23:24:11 +00:00
plugin Fix test when accessing patched plugin too fast 2022-02-25 14:52:34 +02:00
serialization Activate tst_qxmlstream for Android 2022-03-02 14:55:00 +01:00
text Add compile-time checks for QLatin1String 2022-03-02 22:22:36 +01:00
thread Core: Fix tests that did break because QProcess security fix 2022-02-24 09:49:52 +02:00
time Expand testing of QDateTime's isNull() and isValid() 2022-02-18 17:44:53 +01:00
tools Associative containers: add a way to obtain a key/value range 2022-03-04 00:21:44 +01:00
CMakeLists.txt Add tests for QAndroidApplication's sdkVersion and activity 2021-05-13 01:41:36 +03:00