[libcxx-commits] [libcxx] [libc++] Fix the handling of `views::take` for `iota_view` (PR #75683)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Dec 15 19:19:21 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 433498ce4619d0269977ad6dd273c584301d546f db8bbfc8b08673bb3c9637ea75071286c8f4ca48 -- libcxx/include/__ranges/take_view.h libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libcxx/include/__ranges/take_view.h b/libcxx/include/__ranges/take_view.h
index d2764923fa..2ddcf2481b 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -281,26 +281,20 @@ struct __fn {
   template <class _Range,
             convertible_to<range_difference_t<_Range>> _Np,
             class _RawRange = remove_cvref_t<_Range>,
-            class _Dist = range_difference_t<_Range>>
-    requires (!__is_empty_view<_RawRange> &&
-              random_access_range<_RawRange> &&
-              sized_range<_RawRange> &&
-              __is_iota_specialization<_RawRange>)
-  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI
-  constexpr auto operator()(_Range&& __rng, _Np&& __n) const
-    noexcept(noexcept(ranges::iota_view(
-                              *ranges::begin(__rng),
-                              *(ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)))
-                              )))
-    -> decltype(      ranges::iota_view(
-                              // Note: deliberately not forwarding `__rng` to guard against double moves.
-                              *ranges::begin(__rng),
-                              *(ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)))
-                              ))
-    { return          ranges::iota_view(
-                              *ranges::begin(__rng),
-                              *(ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)))
-                              ); }
+            class _Dist     = range_difference_t<_Range>>
+    requires(!__is_empty_view<_RawRange> && random_access_range<_RawRange> && sized_range<_RawRange> &&
+             __is_iota_specialization<_RawRange>)
+  [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __rng, _Np&& __n) const noexcept(noexcept(
+      ranges::iota_view(*ranges::begin(__rng),
+                        *(ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))))))
+      -> decltype(ranges::iota_view(
+          // Note: deliberately not forwarding `__rng` to guard against double moves.
+          *ranges::begin(__rng),
+          *(ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))))) {
+    return ranges::iota_view(
+        *ranges::begin(__rng),
+        *(ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n))));
+  }
 // clang-format off
 #if _LIBCPP_STD_VER >= 23
   // [range.take.overview]: the `repeat_view` "_RawRange models sized_range" case.
diff --git a/libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp b/libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp
index 7c108bd5d0..bb5b5f5ff4 100644
--- a/libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp
+++ b/libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp
@@ -173,7 +173,7 @@ constexpr bool test() {
   {
     auto iota = std::views::iota(1, 8);
     // The second template argument of the resulting `iota_view` is same as the first.
-    using Result = std::ranges::iota_view<int, int>;
+    using Result                               = std::ranges::iota_view<int, int>;
     std::same_as<Result> decltype(auto) result = iota | std::views::take(3);
     assert(result.size() == 3);
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/75683


More information about the libcxx-commits mailing list