[libcxx-commits] [libcxx] [libc++][ranges] Implement LWG4053 and LWG4054 (PR #88612)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Apr 15 20:48:30 PDT 2024
================
@@ -60,6 +60,14 @@ static_assert(!std::is_invocable_v<decltype(std::views::repeat), NonCopyable>);
// Tp is move_constructible
static_assert(std::is_invocable_v<decltype(std::views::repeat), MoveOnly>);
+// LWG4053: Unary call to std::views::repeat does not decay the argument
+using RPV = std::ranges::repeat_view<const char*>;
+
+static_assert(std::same_as<decltype(std::views::repeat("foo", std::unreachable_sentinel)), RPV>); // OK
+static_assert(std::same_as<decltype(std::views::repeat(+"foo", std::unreachable_sentinel)), RPV>); // OK
+static_assert(std::same_as<decltype(std::views::repeat("foo")), RPV>); // OK since LWG4053
+static_assert(std::same_as<decltype(std::views::repeat(+"foo")), RPV>); // OK
----------------
frederick-vs-ja wrote:
> Does the follow case also well-formed?
>
> ```
> static_assert(std::same_as<decltype(std::ranges::repeat_view(std::ranges::repeat_view(1))), std::ranges::repeat_view<std::ranges::repeat_view<int>>>);
> ```
No. The copy deduction candidate is selected here, so the deduced type is `std::ranges::repeat_view<int>`.
This is an unavoidable divergence between `views::repeat` and CTAD for `repeat_view`, and user code should always use `views::repeat`.
https://github.com/llvm/llvm-project/pull/88612
More information about the libcxx-commits
mailing list