[libc++][test] zip_view test cleanups
authorCasey Carter <Casey@Carter.net>
Sun, 8 Jan 2023 07:12:21 +0000 (23:12 -0800)
committerCasey Carter <Casey@Carter.net>
Sun, 8 Jan 2023 23:34:30 +0000 (15:34 -0800)
* The reference type of `common_input_iterator<const int*>` can't be `int&`, because an lvalue of type `const int` _can't_ bind to an `int&`. Fix by changing the return type of `operator*` to `decltype(auto)` to make it fully generic.
* `range.zip/iterator/compare.pass.cpp` verifies that the iterators of a `zip_view` don't support `<=>` when the underlying iterators do not; this is not true after LWG-3692.
* libc++ doesn't yet implement P2165R4 "Compatibility between tuple, pair and tuple-like objects", so the tests expect `zip_view` to use `pair` in places where the working draft requires `tuple`.

Differential Revision: https://reviews.llvm.org/D141216

libcxx/test/std/ranges/range.adaptors/range.zip/cpo.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip/ctor.default.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip/iterator/compare.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip/iterator/deref.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip/iterator/member_types.compile.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip/iterator/subscript.pass.cpp
libcxx/test/std/ranges/range.adaptors/range.zip/types.h

index dec9615..ea5953c 100644 (file)
@@ -63,7 +63,11 @@ constexpr bool test() {
         std::ranges::zip_view<std::ranges::zip_view<SizedRandomAccessView, SizedRandomAccessView>>> decltype(auto) v2 =
         std::views::zip(v);
 
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<std::ranges::range_reference_t<decltype(v2)>, std::tuple<std::pair<int&, int&>>>);
+#else
+    static_assert(std::is_same_v<std::ranges::range_reference_t<decltype(v2)>, std::tuple<std::tuple<int&, int&>>>);
+#endif
   }
   return true;
 }
index 2f8b702..f532896 100644 (file)
@@ -50,10 +50,14 @@ constexpr bool test() {
     View v = View(); // the default constructor is not explicit
     assert(v.size() == 3);
     auto it = v.begin();
-    using Pair = std::pair<const int&, const int&>;
-    assert(*it++ == Pair(buff[0], buff[0]));
-    assert(*it++ == Pair(buff[1], buff[1]));
-    assert(*it == Pair(buff[2], buff[2]));
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
+    using Value = std::pair<const int&, const int&>;
+#else
+    using Value = std::tuple<const int&, const int&>;
+#endif
+    assert(*it++ == Value(buff[0], buff[0]));
+    assert(*it++ == Value(buff[1], buff[1]));
+    assert(*it == Value(buff[2], buff[2]));
   }
 
   return true;
index f39c635..19b5b99 100644 (file)
@@ -163,7 +163,12 @@ constexpr bool test() {
     using Subrange = std::ranges::subrange<It>;
     static_assert(!std::three_way_comparable<It>);
     using R = std::ranges::zip_view<Subrange, Subrange>;
+#ifdef _LIBCPP_VERSION
+    // libc++ hasn't implemented LWG-3692 "zip_view::iterator's operator<=> is overconstrained"
     static_assert(!std::three_way_comparable<std::ranges::iterator_t<R>>);
+#else
+    static_assert(std::three_way_comparable<std::ranges::iterator_t<R>>);
+#endif
 
     int a[] = {1, 2, 3, 4};
     int b[] = {5, 6, 7, 8, 9};
index 26fdace..569d040 100644 (file)
@@ -42,7 +42,11 @@ constexpr bool test() {
     auto [x, y] = *it;
     assert(&x == &(a[0]));
     assert(&y == &(b[0]));
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(*it), std::pair<int&, double&>>);
+#else
+    static_assert(std::is_same_v<decltype(*it), std::tuple<int&, double&>>);
+#endif
 
     x = 5;
     y = 0.1;
@@ -66,7 +70,11 @@ constexpr bool test() {
     auto it = v.begin();
     assert(&(std::get<0>(*it)) == &(a[0]));
     assert(&(std::get<1>(*it)) == &(a[0]));
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(*it), std::pair<int&, int const&>>);
+#else
+    static_assert(std::is_same_v<decltype(*it), std::tuple<int&, int const&>>);
+#endif
   }
   return true;
 }
index b041295..6b0c086 100644 (file)
@@ -73,7 +73,11 @@ void test() {
     static_assert(std::is_same_v<Iter::iterator_concept, std::random_access_iterator_tag>);
     static_assert(std::is_same_v<Iter::iterator_category, std::input_iterator_tag>);
     static_assert(std::is_same_v<Iter::difference_type, std::ptrdiff_t>);
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<Iter::value_type, std::pair<int, int>>);
+#else
+    static_assert(std::is_same_v<Iter::value_type, std::tuple<int, int>>);
+#endif
     static_assert(HasIterCategory<Iter>);
   }
 
@@ -120,7 +124,11 @@ void test() {
     static_assert(std::is_same_v<Iter::iterator_concept, std::random_access_iterator_tag>);
     static_assert(std::is_same_v<Iter::iterator_category, std::input_iterator_tag>);
     static_assert(std::is_same_v<Iter::difference_type, std::ptrdiff_t>);
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<Iter::value_type, std::pair<int, std::pair<int, int>>>);
+#else
+    static_assert(std::is_same_v<Iter::value_type, std::tuple<int, std::tuple<int, int>>>);
+#endif
     static_assert(HasIterCategory<Iter>);
   }
 
@@ -161,7 +169,11 @@ void test() {
     // value_type of multiple views with different value_type
     std::ranges::zip_view v{foos, bars};
     using Iter = decltype(v.begin());
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<Iter::value_type, std::pair<Foo, Bar>>);
+#else
+    static_assert(std::is_same_v<Iter::value_type, std::tuple<Foo, Bar>>);
+#endif
   }
 
   {
index 54172c2..1538d76 100644 (file)
@@ -27,7 +27,11 @@ constexpr bool test() {
     assert(it[2] == *(it + 2));
     assert(it[4] == *(it + 4));
 
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(it[2]), std::pair<int&, int>>);
+#else
+    static_assert(std::is_same_v<decltype(it[2]), std::tuple<int&, int>>);
+#endif
   }
 
   {
@@ -38,7 +42,11 @@ constexpr bool test() {
     assert(it[2] == *(it + 2));
     assert(it[4] == *(it + 4));
 
+#ifdef _LIBCPP_VERSION // libc++ doesn't implement P2165R4 yet
     static_assert(std::is_same_v<decltype(it[2]), std::pair<int&, int&>>);
+#else
+    static_assert(std::is_same_v<decltype(it[2]), std::tuple<int&, int&>>);
+#endif
   }
 
   {
index 47c88e9..20f8c70 100644 (file)
@@ -319,7 +319,7 @@ struct common_input_iterator {
   }
   constexpr void operator++(int) { ++it_; }
 
-  constexpr int& operator*() const { return *it_; }
+  constexpr decltype(auto) operator*() const { return *it_; }
 
   friend constexpr bool operator==(common_input_iterator const&, common_input_iterator const&) = default;
 };