[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:17:30 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: A. Jiang (frederick-vs-ja)
<details>
<summary>Changes</summary>
Fixes #<!-- -->75611.
---
Full diff: https://github.com/llvm/llvm-project/pull/75683.diff
2 Files Affected:
- (modified) libcxx/include/__ranges/take_view.h (+3-3)
- (modified) libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp (+2-3)
``````````diff
diff --git a/libcxx/include/__ranges/take_view.h b/libcxx/include/__ranges/take_view.h
index 518375d684abdd..d2764923fad366 100644
--- a/libcxx/include/__ranges/take_view.h
+++ b/libcxx/include/__ranges/take_view.h
@@ -290,16 +290,16 @@ struct __fn {
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))
+ *(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))
+ *(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))
+ *(ranges::begin(__rng) + std::min<_Dist>(ranges::distance(__rng), std::forward<_Np>(__n)))
); }
// clang-format off
#if _LIBCPP_STD_VER >= 23
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 8ffac8d8fab153..7c108bd5d0a9aa 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
@@ -172,9 +172,8 @@ constexpr bool test() {
// `views::take(iota_view, n)` returns an `iota_view`.
{
auto iota = std::views::iota(1, 8);
- // The second template argument of the resulting `iota_view` is different because it has to be able to hold
- // the `range_difference_t` of the input `iota_view`.
- using Result = std::ranges::iota_view<int, std::ranges::range_difference_t<decltype(iota)>>;
+ // The second template argument of the resulting `iota_view` is same as the first.
+ 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