From b1cf7285f9a469b8f0c62f2048e4c0828def5f1a Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Wed, 22 Dec 2021 16:01:23 +0100 Subject: 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 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 Reviewed-by: Fabian Kosmale --- src/corelib/tools/qlist.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/corelib/tools/qlist.h') 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 &; -- cgit v1.2.3