[libcxx-commits] [libcxx] cf9ee87 - [libc++][test] Move `common_input_iterator` to `test_iterators.h`
Joe Loser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jan 10 16:16:30 PST 2023
Author: Joe Loser
Date: 2023-01-10T17:15:04-07:00
New Revision: cf9ee8791e8b64c46f16dea71345330d70a1deb3
URL: https://github.com/llvm/llvm-project/commit/cf9ee8791e8b64c46f16dea71345330d70a1deb3
DIFF: https://github.com/llvm/llvm-project/commit/cf9ee8791e8b64c46f16dea71345330d70a1deb3.diff
LOG: [libc++][test] Move `common_input_iterator` to `test_iterators.h`
There's a bit of duplication in use of `common_input_iterator` as noted in
https://reviews.llvm.org/D141216. Lift `common_input_iterator` into
`test_iterators.h`.
Differential Revision: https://reviews.llvm.org/D141238
Added:
Modified:
libcxx/test/std/ranges/range.adaptors/range.join.view/types.h
libcxx/test/std/ranges/range.adaptors/range.zip/types.h
libcxx/test/support/test_iterators.h
Removed:
################################################################################
diff --git a/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h b/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h
index d33653858074b..6f4a0a880c4af 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h
+++ b/libcxx/test/std/ranges/range.adaptors/range.join.view/types.h
@@ -196,29 +196,6 @@ struct BufferView : std::ranges::view_base {
}
};
-// an `input_iterator` that can be used in a `common_range`
-template <class Base>
-struct common_input_iterator {
- Base it_;
-
- using value_type = std::iter_value_t<Base>;
- using
diff erence_type = std::intptr_t;
- using iterator_concept = std::input_iterator_tag;
-
- constexpr common_input_iterator() = default;
- constexpr explicit common_input_iterator(Base it) : it_(it) {}
-
- constexpr common_input_iterator& operator++() {
- ++it_;
- return *this;
- }
- constexpr void operator++(int) { ++it_; }
-
- constexpr std::iter_reference_t<Base> operator*() const { return *it_; }
-
- friend constexpr bool operator==(common_input_iterator const&, common_input_iterator const&) = default;
-};
-
using InputCommonInner = BufferView<common_input_iterator<int*>>;
static_assert(std::ranges::input_range<InputCommonInner>);
static_assert(!std::ranges::forward_range<InputCommonInner>);
diff --git a/libcxx/test/std/ranges/range.adaptors/range.zip/types.h b/libcxx/test/std/ranges/range.adaptors/range.zip/types.h
index 20f8c708bab1b..299ffeac0489a 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.zip/types.h
+++ b/libcxx/test/std/ranges/range.adaptors/range.zip/types.h
@@ -302,29 +302,7 @@ static_assert(std::ranges::contiguous_range<ContiguousNonCommonSized>);
static_assert(!std::ranges::common_range<ContiguousNonCommonSized>);
static_assert(std::ranges::sized_range<ContiguousNonCommonSized>);
-template <class Base = int*>
-struct common_input_iterator {
- Base it_;
-
- using value_type = int;
- using
diff erence_type = std::intptr_t;
- using iterator_concept = std::input_iterator_tag;
-
- constexpr common_input_iterator() = default;
- constexpr explicit common_input_iterator(Base it) : it_(it) {}
-
- constexpr common_input_iterator& operator++() {
- ++it_;
- return *this;
- }
- constexpr void operator++(int) { ++it_; }
-
- constexpr decltype(auto) operator*() const { return *it_; }
-
- friend constexpr bool operator==(common_input_iterator const&, common_input_iterator const&) = default;
-};
-
-using InputCommonView = BasicView<common_input_iterator<>>;
+using InputCommonView = BasicView<common_input_iterator<int*>>;
static_assert(std::ranges::input_range<InputCommonView>);
static_assert(!std::ranges::forward_range<InputCommonView>);
static_assert(std::ranges::common_range<InputCommonView>);
@@ -337,7 +315,7 @@ static_assert(!std::ranges::forward_range<NonSimpleInputCommonView>);
static_assert(std::ranges::common_range<NonSimpleInputCommonView>);
LIBCPP_STATIC_ASSERT(!std::ranges::__simple_view<NonSimpleInputCommonView>);
-using InputNonCommonView = BasicView<common_input_iterator<>, sentinel_wrapper<common_input_iterator<>>>;
+using InputNonCommonView = BasicView<common_input_iterator<int*>, sentinel_wrapper<common_input_iterator<int*>>>;
static_assert(std::ranges::input_range<InputNonCommonView>);
static_assert(!std::ranges::forward_range<InputNonCommonView>);
static_assert(!std::ranges::common_range<InputNonCommonView>);
diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h
index 369393d3d5d4e..bc197e664af06 100644
--- a/libcxx/test/support/test_iterators.h
+++ b/libcxx/test/support/test_iterators.h
@@ -697,6 +697,33 @@ cpp20_output_iterator(It) -> cpp20_output_iterator<It>;
static_assert(std::output_iterator<cpp20_output_iterator<int*>, int>);
+# if TEST_STD_VER >= 20
+
+// An `input_iterator` that can be used in a `std::ranges::common_range`
+template <class Base>
+struct common_input_iterator {
+ Base it_;
+
+ using value_type = std::iter_value_t<Base>;
+ using
diff erence_type = std::intptr_t;
+ using iterator_concept = std::input_iterator_tag;
+
+ constexpr common_input_iterator() = default;
+ constexpr explicit common_input_iterator(Base it) : it_(it) {}
+
+ constexpr common_input_iterator& operator++() {
+ ++it_;
+ return *this;
+ }
+ constexpr void operator++(int) { ++it_; }
+
+ constexpr decltype(auto) operator*() const { return *it_; }
+
+ friend constexpr bool operator==(common_input_iterator const&, common_input_iterator const&) = default;
+};
+
+# endif // TEST_STD_VER >= 20
+
// Iterator adaptor that counts the number of times the iterator has had a successor/predecessor
// operation called. Has two recorders:
// * `stride_count`, which records the total number of calls to an op++, op--, op+=, or op-=.
More information about the libcxx-commits
mailing list