[libcxx-commits] [libcxx] c7aa8b2 - [libc++][NFC] Remove duplication of distance_apriori_sentinel

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


Author: Louis Dionne
Date: 2022-01-13T12:23:33-05:00
New Revision: c7aa8b2962b385dd12602ecb88d176529c2f54bc

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

LOG: [libc++][NFC] Remove duplication of distance_apriori_sentinel

Added: 
    libcxx/test/std/iterators/iterator.primitives/range.iter.ops/types.h

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

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
index cdaef2e08662d..a3fa813740986 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_count_sentinel.pass.cpp
@@ -18,33 +18,10 @@
 #include <climits>
 
 #include "test_iterators.h"
+#include "../types.h"
 
 using range_t = std::array<int, 10>;
 
-class distance_apriori_sentinel {
-public:
-  distance_apriori_sentinel() = default;
-  constexpr explicit distance_apriori_sentinel(std::ptr
diff _t const count) : count_(count) {}
-
-  constexpr bool operator==(std::input_or_output_iterator auto const&) const {
-    assert(false && "
diff erence op should take precedence");
-    return false;
-  }
-
-  friend constexpr std::ptr
diff _t operator-(std::input_or_output_iterator auto const&,
-                                            distance_apriori_sentinel const y) {
-    return -y.count_;
-  }
-
-  friend constexpr std::ptr
diff _t operator-(distance_apriori_sentinel const x,
-                                            std::input_or_output_iterator auto const&) {
-    return x.count_;
-  }
-
-private:
-  std::ptr
diff _t count_ = 0;
-};
-
 struct expected_t {
   range_t::const_iterator coordinate;
   std::ptr
diff _t result;

diff  --git a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp
index 90f9aba1b7ff0..71ead2f9f962f 100644
--- a/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/range.iter.ops.advance/iterator_sentinel.pass.cpp
@@ -18,33 +18,10 @@
 #include <cstddef>
 
 #include "test_iterators.h"
+#include "../types.h"
 
 using range_t = std::array<int, 10>;
 
-class distance_apriori_sentinel {
-public:
-  distance_apriori_sentinel() = default;
-  constexpr explicit distance_apriori_sentinel(std::ptr
diff _t const count) : count_(count) {}
-
-  constexpr bool operator==(std::input_or_output_iterator auto const&) const {
-    assert(false && "
diff erence op should take precedence");
-    return false;
-  }
-
-  friend constexpr std::ptr
diff _t operator-(std::input_or_output_iterator auto const&,
-                                            distance_apriori_sentinel const y) {
-    return -y.count_;
-  }
-
-  friend constexpr std::ptr
diff _t operator-(distance_apriori_sentinel const x,
-                                            std::input_or_output_iterator auto const&) {
-    return x.count_;
-  }
-
-private:
-  std::ptr
diff _t count_ = 0;
-};
-
 template <class It, class Sent = It>
 constexpr void check_assignable_case() {
   auto range = range_t{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

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 545e01b547b6b..dcb3c6fee2394 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
@@ -18,6 +18,7 @@
 #include <utility>
 
 #include "test_iterators.h"
+#include "../types.h"
 
 using range_t = std::array<int, 10>;
 
@@ -35,30 +36,6 @@ class assignable_sentinel {
     decltype(base(std::declval<It>())) base_;
 };
 
-class distance_apriori_sentinel {
-public:
-  distance_apriori_sentinel() = default;
-  constexpr explicit distance_apriori_sentinel(std::ptr
diff _t const count) : count_(count) {}
-
-  constexpr bool operator==(std::input_or_output_iterator auto const&) const {
-    assert(false && "
diff erence op should take precedence");
-    return false;
-  }
-
-  friend constexpr std::ptr
diff _t operator-(std::input_or_output_iterator auto const&,
-                                            distance_apriori_sentinel const y) {
-    return -y.count_;
-  }
-
-  friend constexpr std::ptr
diff _t operator-(distance_apriori_sentinel const x,
-                                            std::input_or_output_iterator auto const&) {
-    return x.count_;
-  }
-
-private:
-  std::ptr
diff _t count_ = 0;
-};
-
 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
new file mode 100644
index 0000000000000..2f2f0a87ff89c
--- /dev/null
+++ b/libcxx/test/std/iterators/iterator.primitives/range.iter.ops/types.h
@@ -0,0 +1,40 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef TEST_STD_ITERATORS_ITERATOR_PRIMITIVES_RANGE_ITER_OPS_TYPES_H
+#define TEST_STD_ITERATORS_ITERATOR_PRIMITIVES_RANGE_ITER_OPS_TYPES_H
+
+#include <cassert>
+#include <cstddef>
+#include <iterator>
+
+class distance_apriori_sentinel {
+public:
+  distance_apriori_sentinel() = default;
+  constexpr explicit distance_apriori_sentinel(std::ptr
diff _t const count) : count_(count) {}
+
+  constexpr bool operator==(std::input_or_output_iterator auto const&) const {
+    assert(false && "
diff erence op should take precedence");
+    return false;
+  }
+
+  friend constexpr std::ptr
diff _t operator-(std::input_or_output_iterator auto const&,
+                                            distance_apriori_sentinel const y) {
+    return -y.count_;
+  }
+
+  friend constexpr std::ptr
diff _t operator-(distance_apriori_sentinel const x,
+                                            std::input_or_output_iterator auto const&) {
+    return x.count_;
+  }
+
+private:
+  std::ptr
diff _t count_ = 0;
+};
+
+#endif // TEST_STD_ITERATORS_ITERATOR_PRIMITIVES_RANGE_ITER_OPS_TYPES_H


        


More information about the libcxx-commits mailing list