[libcxx-commits] [libcxx] c0671e2 - [libc++] Move assignable_sentinel to a common header where it can be reused

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 13 09:59:21 PST 2022


Author: Louis Dionne
Date: 2022-01-13T12:59:16-05:00
New Revision: c0671e2c9b5c70fbcda277dcd5321d052ca2a2ee

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

LOG: [libc++] Move assignable_sentinel to a common header where it can be reused

Added: 
    

Modified: 
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/types.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
index dcb3c6fee239..950fd77401a7 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.next/iterator_sentinel.pass.cpp
@@ -22,20 +22,6 @@
 
 using range_t = std::array<int, 10>;
 
-// Sentinel type that can be assigned to an iterator. This is to test the case where
-// std::ranges::next uses assignment instead of successive increments below.
-template <class It>
-class assignable_sentinel {
-public:
-    explicit assignable_sentinel() = default;
-    constexpr explicit assignable_sentinel(const It& it) : base_(base(it)) {}
-    constexpr operator It() const { return It(base_); }
-    constexpr bool operator==(const It& other) const { return base_ == base(other); }
-    friend constexpr It base(const assignable_sentinel& s) { return It(s.base_); }
-private:
-    decltype(base(std::declval<It>())) base_;
-};
-
 template <bool Count, typename It>
 constexpr void check_assignable(int* it, int* last, int const* expected) {
   {

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/types.h b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/types.h
index 2f2f0a87ff89..71704c973451 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/types.h
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/types.h
@@ -12,6 +12,7 @@
 #include <cassert>
 #include <cstddef>
 #include <iterator>
+#include <utility>
 
 class distance_apriori_sentinel {
 public:
@@ -37,4 +38,18 @@ class distance_apriori_sentinel {
   std::ptr
diff _t count_ = 0;
 };
 
+// Sentinel type that can be assigned to an iterator. This is to test the cases where the
+// various iterator operations use assignment instead of successive increments/decrements.
+template <class It>
+class assignable_sentinel {
+public:
+    explicit assignable_sentinel() = default;
+    constexpr explicit assignable_sentinel(const It& it) : base_(base(it)) {}
+    constexpr operator It() const { return It(base_); }
+    constexpr bool operator==(const It& other) const { return base_ == base(other); }
+    friend constexpr It base(const assignable_sentinel& s) { return It(s.base_); }
+private:
+    decltype(base(std::declval<It>())) base_;
+};
+
 #endif // TEST_STD_ITERATORS_ITERATOR_PRIMITIVES_RANGE_ITER_OPS_TYPES_H


        


More information about the libcxx-commits mailing list