summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qlist.h17
-rw-r--r--tests/auto/corelib/tools/qlist/tst_qlist.cpp20
2 files changed, 35 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 &;
diff --git a/tests/auto/corelib/tools/qlist/tst_qlist.cpp b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
index 96a1a35968..d6ff25b830 100644
--- a/tests/auto/corelib/tools/qlist/tst_qlist.cpp
+++ b/tests/auto/corelib/tools/qlist/tst_qlist.cpp
@@ -33,6 +33,26 @@
#include <QScopedValueRollback>
#include <qlist.h>
+
+#if __cplusplus >= 202002L && (!defined(_GLIBCXX_RELEASE) || _GLIBCXX_RELEASE >= 11)
+# if __has_include(<concepts>)
+# include <concepts>
+# if defined(__cpp_concepts)
+ static_assert(std::contiguous_iterator<QList<int>::iterator>);
+ static_assert(std::contiguous_iterator<QList<int>::const_iterator>);
+# endif
+# endif
+# if __has_include(<ranges>)
+# include <ranges>
+# if defined(__cpp_lib_ranges)
+ namespace rns = std::ranges;
+
+ static_assert(rns::contiguous_range<QList<int>>);
+ static_assert(rns::contiguous_range<const QList<int>>);
+# endif
+# endif
+#endif
+
struct Movable {
Movable(char input = 'j')
: i(input)