public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/ranger] libstdc++: Support N3644 "Null Forward Iterators" for testsuite iterators
@ 2020-06-17 19:14 Aldy Hernandez
  0 siblings, 0 replies; only message in thread
From: Aldy Hernandez @ 2020-06-17 19:14 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:e94f2542305ccb5c4a3c4e5e8212713747623417

commit e94f2542305ccb5c4a3c4e5e8212713747623417
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Thu Feb 27 13:01:14 2020 +0000

    libstdc++: Support N3644 "Null Forward Iterators" for testsuite iterators
    
    Comparing value-initialized forward_iterator_wrapper<T> objects fails an
    assertion, but should be valid in C++14 and later.
    
            * testsuite/util/testsuite_iterators.h (forward_iterator_wrapper): Add
            equality comparisons that support value-initialized iterators.

Diff:
---
 libstdc++-v3/ChangeLog                            |  3 +++
 libstdc++-v3/testsuite/util/testsuite_iterators.h | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 0df7126f7c9..946459c3cb8 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,8 @@
 2020-02-27  Jonathan Wakely  <jwakely@redhat.com>
 
+	* testsuite/util/testsuite_iterators.h (forward_iterator_wrapper): Add
+	equality comparisons that support value-initialized iterators.
+
 	* include/bits/boost_concept_check.h (__function_requires): Add
 	_GLIBCXX14_CONSTEXPR.
 	* testsuite/25_algorithms/min/concept_checks.cc: New test.
diff --git a/libstdc++-v3/testsuite/util/testsuite_iterators.h b/libstdc++-v3/testsuite/util/testsuite_iterators.h
index 7b7093919b7..417dff23c50 100644
--- a/libstdc++-v3/testsuite/util/testsuite_iterators.h
+++ b/libstdc++-v3/testsuite/util/testsuite_iterators.h
@@ -337,6 +337,26 @@ namespace __gnu_test
       ++*this;
       return tmp;
     }
+
+#if __cplusplus >= 201402L
+    bool
+    operator==(const forward_iterator_wrapper& it) const noexcept
+    {
+      // Since C++14 value-initialized forward iterators are comparable.
+      if (this->SharedInfo == nullptr || it.SharedInfo == nullptr)
+	return this->SharedInfo == it.SharedInfo && this->ptr == it.ptr;
+
+      const input_iterator_wrapper<T>& base_this = *this;
+      const input_iterator_wrapper<T>& base_that = it;
+      return base_this == base_that;
+    }
+
+    bool
+    operator!=(const forward_iterator_wrapper& it) const noexcept
+    {
+      return !(*this == it);
+    }
+#endif
   };
 
   /**


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-17 19:14 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:14 [gcc/devel/ranger] libstdc++: Support N3644 "Null Forward Iterators" for testsuite iterators 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).