summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qspan_p.h6
-rw-r--r--tests/auto/corelib/tools/qspan/tst_qspan.cpp9
2 files changed, 15 insertions, 0 deletions
diff --git a/src/corelib/tools/qspan_p.h b/src/corelib/tools/qspan_p.h
index ca0a16e7b9..40cadfe79f 100644
--- a/src/corelib/tools/qspan_p.h
+++ b/src/corelib/tools/qspan_p.h
@@ -277,7 +277,9 @@ public:
using reference = element_type&;
using const_reference = const element_type&;
using iterator = pointer; // implementation-defined choice
+ using const_iterator = const_pointer; // implementation-defined choice
using reverse_iterator = std::reverse_iterator<iterator>;
+ using const_reverse_iterator = std::reverse_iterator<const_iterator>;
static constexpr size_type extent = E;
// [span.cons], constructors, copy, and assignment
@@ -298,8 +300,12 @@ public:
// [span.iterators]
[[nodiscard]] constexpr auto begin() const noexcept { return data(); }
[[nodiscard]] constexpr auto end() const noexcept { return data() + size(); }
+ [[nodiscard]] constexpr auto cbegin() const noexcept { return const_iterator{begin()}; }
+ [[nodiscard]] constexpr auto cend() const noexcept { return const_iterator{end()}; }
[[nodiscard]] constexpr auto rbegin() const noexcept { return reverse_iterator{end()}; }
[[nodiscard]] constexpr auto rend() const noexcept { return reverse_iterator{begin()}; }
+ [[nodiscard]] constexpr auto crbegin() const noexcept { return const_reverse_iterator{end()}; }
+ [[nodiscard]] constexpr auto crend() const noexcept { return const_reverse_iterator{begin()}; }
// [span.sub]
template <std::size_t Count>
diff --git a/tests/auto/corelib/tools/qspan/tst_qspan.cpp b/tests/auto/corelib/tools/qspan/tst_qspan.cpp
index aa47c7a01e..04bee9f0d0 100644
--- a/tests/auto/corelib/tools/qspan/tst_qspan.cpp
+++ b/tests/auto/corelib/tools/qspan/tst_qspan.cpp
@@ -159,13 +159,19 @@ void tst_QSpan::check_nonempty_span(QSpan<T, N> s, qsizetype expectedSize) const
QCOMPARE_NE(s.begin(), s.end());
QCOMPARE_NE(s.rbegin(), s.rend());
+ QCOMPARE_NE(s.cbegin(), s.cend());
+ QCOMPARE_NE(s.crbegin(), s.crend());
QCOMPARE_EQ(s.end() - s.begin(), s.size());
+ QCOMPARE_EQ(s.cend() - s.cbegin(), s.size());
QCOMPARE_EQ(s.rend() - s.rbegin(), s.size());
+ QCOMPARE_EQ(s.crend() - s.crbegin(), s.size());
QCOMPARE_EQ(std::addressof(s.front()), std::addressof(*s.begin()));
+ QCOMPARE_EQ(std::addressof(s.front()), std::addressof(*s.cbegin()));
QCOMPARE_EQ(std::addressof(s.front()), std::addressof(s[0]));
QCOMPARE_EQ(std::addressof(s.back()), std::addressof(*s.rbegin()));
+ QCOMPARE_EQ(std::addressof(s.back()), std::addressof(*s.crbegin()));
QCOMPARE_EQ(std::addressof(s.back()), std::addressof(s[s.size() - 1]));
// ### more?
@@ -198,7 +204,9 @@ void tst_QSpan::check_empty_span(QSpan<T, N> s) const
QCOMPARE_EQ(s.size(), 0);
QCOMPARE_EQ(s.begin(), s.end());
+ QCOMPARE_EQ(s.cbegin(), s.cend());
QCOMPARE_EQ(s.rbegin(), s.rend());
+ QCOMPARE_EQ(s.crbegin(), s.crend());
}
template <typename T, std::size_t N>
@@ -264,6 +272,7 @@ void tst_QSpan::check_null_span(QSpan<T, N> s) const
{
QCOMPARE_EQ(s.data(), nullptr);
QCOMPARE_EQ(s.begin(), nullptr);
+ QCOMPARE_EQ(s.cbegin(), nullptr);
QCOMPARE_EQ(s.end(), nullptr);
check_empty_span_incl_subspans(s);
}