[libcxx-commits] [libcxx] [libc++][ranges] Applied `[[nodiscard]]` to `views::zip_transform` (PR #207120)

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sun Jul 5 22:32:39 PDT 2026


https://github.com/H-G-Hristov updated https://github.com/llvm/llvm-project/pull/207120

>From 83e34236209bc1f131a8b52c2b9c0f36ac183c21 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Thu, 2 Jul 2026 08:16:28 +0300
Subject: [PATCH 1/2] [libc++][ranges] Applied `[[nodiscard]]` to
 `views::zip_transform`

`[[nodiscard]]` should be applied to functions where discarding the return value is most likely a correctness issue.

- https://libcxx.llvm.org/CodingGuidelines.html
- https://wg21.link/range.zip.transform

Towards #172124
---
 libcxx/include/__ranges/zip_transform_view.h  | 33 +++----
 .../range.zip.transform/nodiscard.verify.cpp  | 88 +++++++++++++++++++
 2 files changed, 105 insertions(+), 16 deletions(-)
 create mode 100644 libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp

diff --git a/libcxx/include/__ranges/zip_transform_view.h b/libcxx/include/__ranges/zip_transform_view.h
index c56632a2608a1..ffa3e9f9c6dd2 100644
--- a/libcxx/include/__ranges/zip_transform_view.h
+++ b/libcxx/include/__ranges/zip_transform_view.h
@@ -79,15 +79,15 @@ class zip_transform_view : public view_interface<zip_transform_view<_Fn, _Views.
   _LIBCPP_HIDE_FROM_ABI constexpr explicit zip_transform_view(_Fn __fun, _Views... __views)
       : __zip_(std::move(__views)...), __fun_(in_place, std::move(__fun)) {}
 
-  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator<false>(*this, __zip_.begin()); }
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() { return __iterator<false>(*this, __zip_.begin()); }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const
     requires range<const _InnerView> && regular_invocable<const _Fn&, range_reference_t<const _Views>...>
   {
     return __iterator<true>(*this, __zip_.begin());
   }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr auto end() {
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() {
     if constexpr (common_range<_InnerView>) {
       return __iterator<false>(*this, __zip_.end());
     } else {
@@ -95,7 +95,7 @@ class zip_transform_view : public view_interface<zip_transform_view<_Fn, _Views.
     }
   }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto end() const
     requires range<const _InnerView> && regular_invocable<const _Fn&, range_reference_t<const _Views>...>
   {
     if constexpr (common_range<const _InnerView>) {
@@ -105,13 +105,13 @@ class zip_transform_view : public view_interface<zip_transform_view<_Fn, _Views.
     }
   }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr auto size()
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size()
     requires sized_range<_InnerView>
   {
     return __zip_.size();
   }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto size() const
     requires sized_range<const _InnerView>
   {
     return __zip_.size();
@@ -184,7 +184,7 @@ class zip_transform_view<_Fn, _Views...>::__iterator
     requires _Const && convertible_to<__ziperator<false>, __ziperator<_Const>>
       : __parent_(__i.__parent_), __inner_(std::move(__i.__inner_)) {}
 
-  _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator*() const
       noexcept(noexcept(std::apply(__get_deref_and_invoke(), __zip_view_iterator_access::__get_underlying(__inner_)))) {
     return std::apply(__get_deref_and_invoke(), __zip_view_iterator_access::__get_underlying(__inner_));
   }
@@ -233,7 +233,7 @@ class zip_transform_view<_Fn, _Views...>::__iterator
     return *this;
   }
 
-  _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator[](difference_type __n) const
     requires random_access_range<_Base>
   {
     return std::apply(
@@ -255,25 +255,26 @@ class zip_transform_view<_Fn, _Views...>::__iterator
     return __x.__inner_ <=> __y.__inner_;
   }
 
-  _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n)
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(const __iterator& __i, difference_type __n)
     requires random_access_range<_Base>
   {
     return __iterator(*__i.__parent_, __i.__inner_ + __n);
   }
 
-  _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i)
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator+(difference_type __n, const __iterator& __i)
     requires random_access_range<_Base>
   {
     return __iterator(*__i.__parent_, __i.__inner_ + __n);
   }
 
-  _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n)
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr __iterator operator-(const __iterator& __i, difference_type __n)
     requires random_access_range<_Base>
   {
     return __iterator(*__i.__parent_, __i.__inner_ - __n);
   }
 
-  _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y)
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr difference_type
+  operator-(const __iterator& __x, const __iterator& __y)
     requires sized_sentinel_for<__ziperator<_Const>, __ziperator<_Const>>
   {
     return __x.__inner_ - __y.__inner_;
@@ -307,14 +308,14 @@ class zip_transform_view<_Fn, _Views...>::__sentinel {
 
   template <bool _OtherConst>
     requires sized_sentinel_for<__zentinel<_Const>, __ziperator<_OtherConst>>
-  _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>>
   operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) {
     return __x.__inner_ - __y.__inner_;
   }
 
   template <bool _OtherConst>
     requires sized_sentinel_for<__zentinel<_Const>, __ziperator<_OtherConst>>
-  _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>>
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI friend constexpr range_difference_t<__maybe_const<_OtherConst, _InnerView>>
   operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) {
     return __x.__inner_ - __y.__inner_;
   }
@@ -327,14 +328,14 @@ struct __fn {
   template <class _Fn>
     requires(move_constructible<decay_t<_Fn>> && regular_invocable<decay_t<_Fn>&> &&
              is_object_v<invoke_result_t<decay_t<_Fn>&>>)
-  _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&&) const
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&&) const
       noexcept(noexcept(auto(views::empty<decay_t<invoke_result_t<decay_t<_Fn>&>>>))) {
     return views::empty<decay_t<invoke_result_t<decay_t<_Fn>&>>>;
   }
 
   template <class _Fn, class... _Ranges>
     requires(sizeof...(_Ranges) > 0)
-  _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __fun, _Ranges&&... __rs) const
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Fn&& __fun, _Ranges&&... __rs) const
       noexcept(noexcept(zip_transform_view(std::forward<_Fn>(__fun), std::forward<_Ranges>(__rs)...)))
           -> decltype(zip_transform_view(std::forward<_Fn>(__fun), std::forward<_Ranges>(__rs)...)) {
     return zip_transform_view(std::forward<_Fn>(__fun), std::forward<_Ranges>(__rs)...);
diff --git a/libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp b/libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp
new file mode 100644
index 0000000000000..7d15d027f75be
--- /dev/null
+++ b/libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp
@@ -0,0 +1,88 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++23
+
+// Check that functions are marked [[nodiscard]]
+
+#include <ranges>
+#include <utility>
+#include <vector>
+
+struct View : std::ranges::view_interface<View> {
+  int* begin();
+  const int* begin() const;
+  volatile int* end();
+  const volatile int* end() const;
+
+  int size() const;
+};
+static_assert(!std::ranges::common_range<View>);
+static_assert(!std::same_as<std::ranges::iterator_t<View>, std::ranges::iterator_t<const View>>);
+static_assert(!std::same_as<std::ranges::sentinel_t<View>, std::ranges::sentinel_t<const View>>);
+
+template <class... Args>
+struct Invocable {
+  int operator()(Args...) const { return 5; }
+};
+
+void test() {
+  View range;
+  std::ranges::zip_transform_view ztv{[](int x) { return x; }, range};
+
+  // [range.zip_transform.view]
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  ztv.begin();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::as_const(ztv).begin();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  ztv.end();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::as_const(ztv).end();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  ztv.size();
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::as_const(ztv).size();
+
+  // [range.zip_transform.iterator]
+
+  auto it  = ztv.begin();
+  auto cIt = std::as_const(ztv).begin();
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  *cIt;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  cIt[0];
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it + 1;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  1 + it;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it - 1;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it - it;
+
+  // [range.zip_transform.sentinel]
+
+  auto st = ztv.end();
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  it - st;
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  st - it;
+
+  // [range.zip_transform.overview]
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::views::zip_transform(Invocable<>{});
+
+  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+  std::views::zip_transform([](int x) { return x; }, range);
+}
\ No newline at end of file

>From 7595d99fcdce5c0f4856027608807187fd2a3713 Mon Sep 17 00:00:00 2001
From: Hristo Hristov <hghristov.rmm at gmail.com>
Date: Mon, 6 Jul 2026 08:32:19 +0300
Subject: [PATCH 2/2] Try to fix

---
 .../range.zip.transform/nodiscard.verify.cpp  | 124 ++++++++++++------
 .../range.adaptors/range_adaptor_types.h      |  27 ----
 libcxx/test/support/test_iterators.h          |  30 ++++-
 3 files changed, 112 insertions(+), 69 deletions(-)

diff --git a/libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp b/libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp
index 7d15d027f75be..0a85c8802011a 100644
--- a/libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp
+++ b/libcxx/test/libcxx/ranges/range.adaptors/range.zip.transform/nodiscard.verify.cpp
@@ -14,17 +14,40 @@
 #include <utility>
 #include <vector>
 
-struct View : std::ranges::view_interface<View> {
+#include "test_iterators.h"
+
+struct CommonView : std::ranges::view_interface<CommonView> {
   int* begin();
-  const int* begin() const;
-  volatile int* end();
-  const volatile int* end() const;
+  int* begin() const;
+  int* end();
+  int* end() const;
 
   int size() const;
 };
-static_assert(!std::ranges::common_range<View>);
-static_assert(!std::same_as<std::ranges::iterator_t<View>, std::ranges::iterator_t<const View>>);
-static_assert(!std::same_as<std::ranges::sentinel_t<View>, std::ranges::sentinel_t<const View>>);
+static_assert(std::ranges::common_range<CommonView>);
+static_assert(std::same_as<std::ranges::iterator_t<CommonView>, std::ranges::iterator_t<const CommonView>>);
+static_assert(std::same_as<std::ranges::sentinel_t<CommonView>, std::ranges::sentinel_t<const CommonView>>);
+
+struct ForwardSizedNonCommon {
+  int* buffer_      = nullptr;
+  std::size_t size_ = 0;
+
+  template <std::size_t N>
+  constexpr ForwardSizedNonCommon(int (&b)[N]) : buffer_(b), size_(N) {}
+
+  constexpr ForwardSizedNonCommon(int* b, std::size_t s) : buffer_(b), size_(s) {}
+
+  using iterator = forward_sized_iterator<int*>;
+  using sentinel = sized_sentinel<iterator>;
+
+  constexpr iterator begin() const { return iterator(buffer_); }
+  constexpr sentinel end() const { return sentinel(iterator(buffer_ + size_)); }
+};
+static_assert(std::ranges::forward_range<ForwardSizedNonCommon>);
+static_assert(std::ranges::sized_range<ForwardSizedNonCommon>);
+static_assert(!std::ranges::common_range<ForwardSizedNonCommon>);
+static_assert(!std::ranges::random_access_range<ForwardSizedNonCommon>);
+// static_assert(simple_view<ForwardSizedNonCommon>);
 
 template <class... Args>
 struct Invocable {
@@ -32,51 +55,70 @@ struct Invocable {
 };
 
 void test() {
-  View range;
-  std::ranges::zip_transform_view ztv{[](int x) { return x; }, range};
+  CommonView commonRange;
+  std::ranges::zip_transform_view commonZtv{[](int x) { return x; }, commonRange};
+  static_assert(std::same_as<decltype(commonZtv.end()), decltype(commonZtv.begin())>);
 
   // [range.zip_transform.view]
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  ztv.begin();
+  commonZtv.begin();
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::as_const(ztv).begin();
+  std::as_const(commonZtv).begin();
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  ztv.end();
+  commonZtv.end();
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::as_const(ztv).end();
+  std::as_const(commonZtv).end();
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  ztv.size();
+  commonZtv.size();
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::as_const(ztv).size();
+  std::as_const(commonZtv).size();
 
   // [range.zip_transform.iterator]
-
-  auto it  = ztv.begin();
-  auto cIt = std::as_const(ztv).begin();
-
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  *cIt;
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  cIt[0];
-
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  it + 1;
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  1 + it;
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  it - 1;
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  it - it;
+  {
+    auto it  = commonZtv.begin();
+    auto cIt = std::as_const(commonZtv).begin();
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    *cIt;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    cIt[0];
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    it + 1;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    1 + it;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    it - 1;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    it - it;
+  }
 
   // [range.zip_transform.sentinel]
-
-  auto st = ztv.end();
-
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  it - st;
-  // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  st - it;
+  {
+    auto MakeTuple = [](auto&&... args) { return std::tuple(std::forward<decltype(args)>(args)...); };
+    int arr[]      = {1, 2, 3};
+    std::ranges::zip_transform_view nonCommonZtv{MakeTuple, std::views::iota(0, 3), ForwardSizedNonCommon(arr)};
+    static_assert(!std::ranges::common_range<decltype(nonCommonZtv)>);
+    static_assert(!std::same_as<decltype(nonCommonZtv.end()), decltype(nonCommonZtv.begin())>);
+    auto it  = nonCommonZtv.begin();
+    auto cIt = std::as_const(nonCommonZtv).begin();
+    auto st  = nonCommonZtv.end();
+    auto cSt = std::as_const(nonCommonZtv).end();
+
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    it - st;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    st - it;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    it - cSt;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    cSt - it;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    cIt - st;
+    // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
+    st - cIt;
+  }
 
   // [range.zip_transform.overview]
 
@@ -84,5 +126,5 @@ void test() {
   std::views::zip_transform(Invocable<>{});
 
   // expected-warning at +1 {{ignoring return value of function declared with 'nodiscard' attribute}}
-  std::views::zip_transform([](int x) { return x; }, range);
-}
\ No newline at end of file
+  std::views::zip_transform([](int x) { return x; }, commonRange);
+}
diff --git a/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h b/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h
index 0b654566e35b8..429c94e254303 100644
--- a/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h
+++ b/libcxx/test/std/ranges/range.adaptors/range_adaptor_types.h
@@ -208,33 +208,6 @@ struct BasicView : IntBufferView {
   }
 };
 
-template <class Base = int*>
-struct forward_sized_iterator {
-  Base it_ = nullptr;
-
-  using iterator_category = std::forward_iterator_tag;
-  using value_type        = int;
-  using difference_type   = std::intptr_t;
-  using pointer           = Base;
-  using reference         = decltype(*Base{});
-
-  forward_sized_iterator() = default;
-  constexpr forward_sized_iterator(Base it) : it_(it) {}
-
-  constexpr reference operator*() const { return *it_; }
-
-  constexpr forward_sized_iterator& operator++() {
-    ++it_;
-    return *this;
-  }
-  constexpr forward_sized_iterator operator++(int) { return forward_sized_iterator(it_++); }
-
-  friend constexpr bool operator==(const forward_sized_iterator&, const forward_sized_iterator&) = default;
-
-  friend constexpr difference_type operator-(const forward_sized_iterator& x, const forward_sized_iterator& y) {
-    return x.it_ - y.it_;
-  }
-};
 static_assert(std::forward_iterator<forward_sized_iterator<>>);
 static_assert(std::sized_sentinel_for<forward_sized_iterator<>, forward_sized_iterator<>>);
 
diff --git a/libcxx/test/support/test_iterators.h b/libcxx/test/support/test_iterators.h
index 4fc8345c2dcef..6a721a4feaf9f 100644
--- a/libcxx/test/support/test_iterators.h
+++ b/libcxx/test/support/test_iterators.h
@@ -1175,6 +1175,35 @@ class sized_sentinel {
 template <class It>
 sized_sentinel(It) -> sized_sentinel<It>;
 
+
+template <class Base = int*>
+struct forward_sized_iterator {
+  Base it_ = nullptr;
+
+  using iterator_category = std::forward_iterator_tag;
+  using value_type        = int;
+  using difference_type   = std::intptr_t;
+  using pointer           = Base;
+  using reference         = decltype(*Base{});
+
+  forward_sized_iterator() = default;
+  constexpr forward_sized_iterator(Base it) : it_(it) {}
+
+  constexpr reference operator*() const { return *it_; }
+
+  constexpr forward_sized_iterator& operator++() {
+    ++it_;
+    return *this;
+  }
+  constexpr forward_sized_iterator operator++(int) { return forward_sized_iterator(it_++); }
+
+  friend constexpr bool operator==(const forward_sized_iterator&, const forward_sized_iterator&) = default;
+
+  friend constexpr difference_type operator-(const forward_sized_iterator& x, const forward_sized_iterator& y) {
+    return x.it_ - y.it_;
+  }
+};
+
 namespace adl {
 
 class Iterator {
@@ -1880,5 +1909,4 @@ using cpp20_input_iterator_list =
 #endif
 } // namespace types
 
-
 #endif // SUPPORT_TEST_ITERATORS_H



More information about the libcxx-commits mailing list