diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2021-12-22 16:01:23 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-01-13 21:19:24 +0100 |
commit | b1cf7285f9a469b8f0c62f2048e4c0828def5f1a (patch) | |
tree | 768548d84a013ad7c07474136bf6a2a7c765a224 /src/corelib/tools/qlist.h | |
parent | 552c4a9655ea22c354454132a9bda7a1c7c836f7 (diff) |
Properly detect and declare contiguous iterators
The recommended way to detect a contiguous iterator isn't to check
the iterator_category; it's to use the iterator concepts.
Similarly, the recommendation set in place by P2259 (for being
backwards-compatible) is to declare a iterator_concept member,
not to change iterator_category to a C++20 category, (also)
because legacy code may be checking for equality against a specific
category, rather than for convertibility. This is erroneous, but
such code exists, alas.
This is enshrined in C++20's stdlib: for instance, iterator_traits<Foo*>
has random_access_category_tag as iterator_category, but
contiguous_iterator_tag as its iterator_concept.
Hence:
1) in QArrayDataOps use the concept, and not the category, to do
the check
2) when declaring iterators, keep the category as random access,
and introduce the concept alias (if supported).
Pick-to: 6.2 6.3
Change-Id: Ib600da7331d687a15082becaa6be06aefc24bb9c
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 8a2b542357..aaa2a950dd 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -147,12 +147,10 @@ public: using value_type = T; // libstdc++ shipped with gcc < 11 does not have a fix for defect LWG 3346 #if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11) - using iterator_category = std::contiguous_iterator_tag; + using iterator_concept = std::contiguous_iterator_tag; using element_type = value_type; -#else - using iterator_category = std::random_access_iterator_tag; #endif - + using iterator_category = std::random_access_iterator_tag; using pointer = T *; using reference = T &; @@ -220,11 +218,10 @@ public: using value_type = T; // libstdc++ shipped with gcc < 11 does not have a fix for defect LWG 3346 #if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11) - using iterator_category = std::contiguous_iterator_tag; + using iterator_concept = std::contiguous_iterator_tag; using element_type = const value_type; -#else - using iterator_category = std::random_access_iterator_tag; #endif + using iterator_category = std::random_access_iterator_tag; using pointer = const T *; using reference = const T &; |