diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-03-29 14:13:46 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2021-04-06 11:35:35 +0200 |
commit | 595b4e1a9b436a8190964dc41f79621400f5a6be (patch) | |
tree | 6e2c79a7f9ac4a74710024aa287408da95aab6e3 /src/corelib/tools/qlist.h | |
parent | 0eb0fc87014b8de06473055bd2298b2423d480f6 (diff) |
QList: Satisfy contiguous_range requirements
With C++20, there is a new iterator_category: contiguous_iterator, for
containers whose elements are stored contiguously in memory. In Qt 6,
QList satisfies this requirement.
However, we still need to tell the standard machinery about it. Step one
is to mark the iterators as contiguous_iterator; as that exists only in
C++20, we have to ifdef accordingly.
We also have to ensure that the iterators satisfy pointer_traits by
defining element_type due to how contiguous_range is specified. As this
runs afoul of LWG 3346, we check for known bad _GLIBCXX_RELEASE
versions.
Change-Id: I8c134544e694ba937e4d912393eb72fa75b49e3d
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/corelib/tools/qlist.h')
-rw-r--r-- | src/corelib/tools/qlist.h | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 841deb02a1..61a02f795b 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -132,9 +132,16 @@ public: class iterator { T *i = nullptr; public: - using iterator_category = std::random_access_iterator_tag; using difference_type = qsizetype; 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; +#else + using iterator_category = std::random_access_iterator_tag; +#endif + using element_type = value_type; + using pointer = T *; using reference = T &; @@ -167,9 +174,15 @@ public: class const_iterator { const T *i = nullptr; public: - using iterator_category = std::random_access_iterator_tag; using difference_type = qsizetype; 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; +#else + using iterator_category = std::random_access_iterator_tag; +#endif + using element_type = const value_type; using pointer = const T *; using reference = const T &; |