public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/ranger] libstdc++: Add a testsuite range type that has a sized sentinel
@ 2020-06-17 19:24 Aldy Hernandez
0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2020-06-17 19:24 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:26af9cd8af1b3b603434586a17127d8c3d2d8266
commit 26af9cd8af1b3b603434586a17127d8c3d2d8266
Author: Patrick Palka <ppalka@redhat.com>
Date: Mon Mar 2 22:32:22 2020 -0500
libstdc++: Add a testsuite range type that has a sized sentinel
This adds a testsuite range type whose end() is a sized sentinel to
<testsuite_iterators.h>, which will be used in the tests that verify LWG 3355.
libstdc++-v3/ChangeLog:
* testsuite/util/testsuite_iterators.h (test_range::get_iterator): Make
protected instead of private.
(test_sized_range_sized_sent): New.
Diff:
---
libstdc++-v3/ChangeLog | 4 +++
libstdc++-v3/testsuite/util/testsuite_iterators.h | 32 +++++++++++++++++++++++
2 files changed, 36 insertions(+)
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 1d68f7ceaac..ca5f0d0f3f8 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,9 @@
2020-03-04 Patrick Palka <ppalka@redhat.com>
+ * testsuite/util/testsuite_iterators.h (test_range::get_iterator): Make
+ protected instead of private.
+ (test_sized_range_sized_sent): New.
+
* testsuite/util/testsuite_iterators.h (input_iterator_wrapper_nocopy):
New testsuite iterator.
* testsuite/24_iterators/counted_iterator/lwg3389.cc: use it.
diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index e47b2b03e40..a915c02248b 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -735,6 +735,7 @@ namespace __gnu_test
{ return i.ptr - s.end; }
};
+ protected:
auto
get_iterator(T* p)
{
@@ -812,6 +813,37 @@ namespace __gnu_test
using test_output_sized_range
= test_sized_range<T, output_iterator_wrapper>;
+ // A type meeting the minimum std::sized_range requirements, and whose end()
+ // returns a sized sentinel.
+ template<typename T, template<typename> class Iter>
+ struct test_sized_range_sized_sent : test_sized_range<T, Iter>
+ {
+ using test_sized_range<T, Iter>::test_sized_range;
+
+ template<typename I>
+ struct sentinel
+ {
+ T* end;
+
+ friend bool operator==(const sentinel& s, const I& i) noexcept
+ { return s.end == i.ptr; }
+
+ friend std::iter_difference_t<I>
+ operator-(const sentinel& s, const I& i) noexcept
+ { return s.end - i.ptr; }
+
+ friend std::iter_difference_t<I>
+ operator-(const I& i, const sentinel& s) noexcept
+ { return i.ptr - s.end; }
+ };
+
+ auto end() &
+ {
+ using I = decltype(this->get_iterator(this->bounds.last));
+ return sentinel<I>{this->bounds.last};
+ }
+ };
+
// test_range and test_sized_range do not own their elements, so they model
// std::ranges::borrowed_range. This file does not define specializations of
// std::ranges::enable_borrowed_range, so that individual tests can decide
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-06-17 19:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-17 19:24 [gcc/devel/ranger] libstdc++: Add a testsuite range type that has a sized sentinel Aldy Hernandez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).