[libcxx-commits] [libcxx] [libc++] Fix `take_view::__sentinel`'s `operator==` (PR #74655)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 6 23:57:43 PST 2023
================
@@ -0,0 +1,192 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03, c++11, c++14, c++17
+
+// friend constexpr bool operator==(const CI<Const>& y, const sentinel& x);
+// template<bool OtherConst = !Const>
+// requires sentinel_for<sentinel_t<Base>, iterator_t<maybe-const<OtherConst, V>>>
+// friend constexpr bool operator==(const CI<OtherConst>& y, const sentinel& x);
+
+#include <cassert>
+#include <cstddef>
+#include <ranges>
+#include <type_traits>
+#include <utility>
+
+#include "test_iterators.h"
+
+template <bool Const>
+class StrictIterator {
+ using Base = std::conditional_t<Const, const int*, int*>;
+ Base base_;
+
+public:
+ using value_type = int;
+ using difference_type = std::ptrdiff_t;
+
+ constexpr explicit StrictIterator(Base base) : base_(base) {}
+
+ StrictIterator(StrictIterator&&) = default;
+ StrictIterator& operator=(StrictIterator&&) = default;
+
+ constexpr StrictIterator& operator++() {
+ ++base_;
+ return *this;
+ }
+
+ constexpr void operator++(int) { ++*this; }
+ constexpr decltype(auto) operator*() const { return *base_; }
+ constexpr Base base() const { return base_; }
+};
+
+static_assert(std::input_iterator<StrictIterator<false>>);
+static_assert(!std::copyable<StrictIterator<false>>);
+static_assert(!std::forward_iterator<StrictIterator<false>>);
+static_assert(std::input_iterator<StrictIterator<true>>);
+static_assert(!std::copyable<StrictIterator<true>>);
+static_assert(!std::forward_iterator<StrictIterator<true>>);
+
+template <bool Const>
+class StrictSentinel {
----------------
huixie90 wrote:
I found the name StrictSentinel a bit confusing. It is actually not strict because it supports all the cross-const comparison with iterator.
https://github.com/llvm/llvm-project/pull/74655
More information about the libcxx-commits
mailing list