QSpan: add C++23 c{,r}{begin,end}()
It was weird that they were missing. Now that C++23 added them to std::span, add them to QSpan, too. Change-Id: I4a9b1fdeda66bc7b133c8f7b3b269656e5faffa3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 368ea559ebe842500fcad962d02308c7cb2f5632) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
b539aa0192
commit
b821985ad6
@ -277,7 +277,9 @@ public:
|
|||||||
using reference = element_type&;
|
using reference = element_type&;
|
||||||
using const_reference = const element_type&;
|
using const_reference = const element_type&;
|
||||||
using iterator = pointer; // implementation-defined choice
|
using iterator = pointer; // implementation-defined choice
|
||||||
|
using const_iterator = const_pointer; // implementation-defined choice
|
||||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||||
|
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||||
static constexpr size_type extent = E;
|
static constexpr size_type extent = E;
|
||||||
|
|
||||||
// [span.cons], constructors, copy, and assignment
|
// [span.cons], constructors, copy, and assignment
|
||||||
@ -298,8 +300,12 @@ public:
|
|||||||
// [span.iterators]
|
// [span.iterators]
|
||||||
[[nodiscard]] constexpr auto begin() const noexcept { return data(); }
|
[[nodiscard]] constexpr auto begin() const noexcept { return data(); }
|
||||||
[[nodiscard]] constexpr auto end() const noexcept { return data() + size(); }
|
[[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 rbegin() const noexcept { return reverse_iterator{end()}; }
|
||||||
[[nodiscard]] constexpr auto rend() const noexcept { return reverse_iterator{begin()}; }
|
[[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]
|
// [span.sub]
|
||||||
template <std::size_t Count>
|
template <std::size_t Count>
|
||||||
|
@ -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.begin(), s.end());
|
||||||
QCOMPARE_NE(s.rbegin(), s.rend());
|
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.end() - s.begin(), s.size());
|
||||||
|
QCOMPARE_EQ(s.cend() - s.cbegin(), s.size());
|
||||||
QCOMPARE_EQ(s.rend() - s.rbegin(), 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.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.front()), std::addressof(s[0]));
|
||||||
QCOMPARE_EQ(std::addressof(s.back()), std::addressof(*s.rbegin()));
|
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]));
|
QCOMPARE_EQ(std::addressof(s.back()), std::addressof(s[s.size() - 1]));
|
||||||
|
|
||||||
// ### more?
|
// ### more?
|
||||||
@ -198,7 +204,9 @@ void tst_QSpan::check_empty_span(QSpan<T, N> s) const
|
|||||||
QCOMPARE_EQ(s.size(), 0);
|
QCOMPARE_EQ(s.size(), 0);
|
||||||
|
|
||||||
QCOMPARE_EQ(s.begin(), s.end());
|
QCOMPARE_EQ(s.begin(), s.end());
|
||||||
|
QCOMPARE_EQ(s.cbegin(), s.cend());
|
||||||
QCOMPARE_EQ(s.rbegin(), s.rend());
|
QCOMPARE_EQ(s.rbegin(), s.rend());
|
||||||
|
QCOMPARE_EQ(s.crbegin(), s.crend());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, std::size_t N>
|
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.data(), nullptr);
|
||||||
QCOMPARE_EQ(s.begin(), nullptr);
|
QCOMPARE_EQ(s.begin(), nullptr);
|
||||||
|
QCOMPARE_EQ(s.cbegin(), nullptr);
|
||||||
QCOMPARE_EQ(s.end(), nullptr);
|
QCOMPARE_EQ(s.end(), nullptr);
|
||||||
check_empty_span_incl_subspans(s);
|
check_empty_span_incl_subspans(s);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user