[libcxx-commits] [libcxx] 7893bb7 - [libc++] Refactor the test for join_view's default constructor

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 10 06:02:51 PST 2022


Author: Louis Dionne
Date: 2022-01-10T09:02:45-05:00
New Revision: 7893bb74081309cc8d038ed84cefd7c6e4c155c3

URL: https://github.com/llvm/llvm-project/commit/7893bb74081309cc8d038ed84cefd7c6e4c155c3
DIFF: https://github.com/llvm/llvm-project/commit/7893bb74081309cc8d038ed84cefd7c6e4c155c3.diff

LOG: [libc++] Refactor the test for join_view's default constructor

In particular, this removes the need for adding a ad-hoc `operator==`
to forward_iterator.

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

Added: 
    

Modified: 
    libcxx/test/std/ranges/range.adaptors/range.join.view/iterator/ctor.default.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/ranges/range.adaptors/range.join.view/iterator/ctor.default.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.join.view/iterator/ctor.default.pass.cpp
index 709e2f925a67c..29ea95ea605aa 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.join.view/iterator/ctor.default.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.join.view/iterator/ctor.default.pass.cpp
@@ -12,45 +12,46 @@
 
 // iterator() requires default_initializable<OuterIter> = default;
 
-#include <cassert>
 #include <ranges>
 
-#include "test_macros.h"
+#include <cassert>
+#include <type_traits>
+#include "test_iterators.h"
 #include "../types.h"
 
-template<class T>
-struct DefaultCtorParent : std::ranges::view_base {
-  T *ptr_;
-  constexpr DefaultCtorParent(T *ptr) : ptr_(ptr) {}
-
-  constexpr forward_iterator<T *> begin() { return forward_iterator<T *>(ptr_); }
-  constexpr forward_iterator<const T *> begin() const { return forward_iterator<const T *>(ptr_); }
-  constexpr T *end() { return ptr_ + 4; }
-  constexpr const T *end() const { return ptr_ + 4; }
+template <class It>
+struct view : std::ranges::view_base {
+  It begin() const;
+  sentinel_wrapper<It> end() const;
 };
 
-template<class T>
-constexpr bool operator==(const forward_iterator<T*> &lhs, const T *rhs) { return lhs.base() == rhs; }
-template<class T>
-constexpr bool operator==(const T *lhs, const forward_iterator<T*> &rhs) { return rhs.base() == lhs; }
-
-constexpr bool test() {
-  using Base = DefaultCtorParent<ChildView>;
-  // Note, only the outer iterator is default_initializable:
-  static_assert( std::default_initializable<std::ranges::iterator_t<Base>>);
-  static_assert(!std::default_initializable<std::ranges::iterator_t<std::ranges::range_reference_t<Base>>>);
-
-  std::ranges::iterator_t<std::ranges::join_view<Base>> iter1;
-  (void) iter1;
+template <class It>
+constexpr void test_default_constructible() {
+  using JoinView = std::ranges::join_view<view<It>>;
+  using JoinIterator = std::ranges::iterator_t<JoinView>;
+  static_assert(std::is_default_constructible_v<JoinIterator>);
+  JoinIterator it; (void)it;
+}
 
-  static_assert(!std::default_initializable<std::ranges::iterator_t<std::ranges::join_view<ParentView<ChildView>>>>);
+template <class It>
+constexpr void test_non_default_constructible() {
+  using JoinView = std::ranges::join_view<view<It>>;
+  using JoinIterator = std::ranges::iterator_t<JoinView>;
+  static_assert(!std::is_default_constructible_v<JoinIterator>);
+}
 
+constexpr bool test() {
+  test_non_default_constructible<cpp17_input_iterator<ChildView*>>();
+  // NOTE: cpp20_input_iterator can't be used with join_view because it is not copyable.
+  test_default_constructible<forward_iterator<ChildView*>>();
+  test_default_constructible<bidirectional_iterator<ChildView*>>();
+  test_default_constructible<random_access_iterator<ChildView*>>();
+  test_default_constructible<contiguous_iterator<ChildView*>>();
   return true;
 }
 
 int main(int, char**) {
   test();
   static_assert(test());
-
   return 0;
 }


        


More information about the libcxx-commits mailing list