[libcxx-commits] [libcxx] [libc++][ranges] implement `std::ranges::zip_transform_view` (PR #79605)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jul 11 11:02:50 PDT 2025
================
@@ -0,0 +1,142 @@
+//===----------------------------------------------------------------------===//
+//
+// 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, c++20
+
+// template<bool OtherConst>
+// requires sentinel_for<zentinel<Const>, ziperator<OtherConst>>
+// friend constexpr bool operator==(const iterator<OtherConst>& x, const sentinel& y);
+
+#include <cassert>
+#include <compare>
+#include <ranges>
+
+#include "../types.h"
+
+using Iterator = random_access_iterator<int*>;
+using ConstIterator = random_access_iterator<const int*>;
+
+template <bool Const>
+struct ComparableSentinel {
+ using Iter = std::conditional_t<Const, ConstIterator, Iterator>;
+ Iter iter_;
+
+ explicit ComparableSentinel() = default;
+ constexpr explicit ComparableSentinel(const Iter& it) : iter_(it) {}
+
+ constexpr friend bool operator==(const Iterator& i, const ComparableSentinel& s) { return base(i) == base(s.iter_); }
+
+ constexpr friend bool operator==(const ConstIterator& i, const ComparableSentinel& s) {
+ return base(i) == base(s.iter_);
+ }
+};
+
+struct ComparableView : IntBufferView {
+ using IntBufferView::IntBufferView;
+
+ constexpr auto begin() { return Iterator(buffer_); }
+ constexpr auto begin() const { return ConstIterator(buffer_); }
+ constexpr auto end() { return ComparableSentinel<false>(Iterator(buffer_ + size_)); }
+ constexpr auto end() const { return ComparableSentinel<true>(ConstIterator(buffer_ + size_)); }
+};
+
+struct ConstIncompatibleView : std::ranges::view_base {
+ cpp17_input_iterator<int*> begin();
+ forward_iterator<const int*> begin() const;
+ sentinel_wrapper<cpp17_input_iterator<int*>> end();
+ sentinel_wrapper<forward_iterator<const int*>> end() const;
+};
+
+template <class Iter, class Sent>
+concept EqualComparable = std::invocable<std::equal_to<>, const Iter&, const Sent&>;
+
+constexpr bool test() {
+ int buffer1[4] = {1, 2, 3, 4};
+ int buffer2[5] = {1, 2, 3, 4, 5};
+ int buffer3[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+ {
----------------
ldionne wrote:
Let's test comparison with a `zip_transform_view` over a single range? Also an empty range?
https://github.com/llvm/llvm-project/pull/79605
More information about the libcxx-commits
mailing list