libstdc++: Support N3644 "Null Forward Iterators" for testsuite iterators
authorJonathan Wakely <jwakely@redhat.com>
Thu, 27 Feb 2020 13:01:14 +0000 (13:01 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 27 Feb 2020 13:01:14 +0000 (13:01 +0000)
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.

libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/util/testsuite_iterators.h

index 0df7126f7c9a1e0b257f1539c12bc8de0ede207c..946459c3cb8e08015d1887b6ede493588d027ac0 100644 (file)
@@ -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.
index 7b7093919b79185d53db85c5ca56316b765dd8a7..417dff23c500ef05a1c3f0eefff7380b840f7502 100644 (file)
@@ -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
   };
 
   /**