[libcxx-commits] [libcxx] [libc++][ranges] Fix missing `forward` in `views::enumerate` (PR #197635)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 14 18:53:33 PDT 2026
================
@@ -90,6 +90,26 @@ static_assert(!std::is_invocable_v<decltype(std::views::enumerate), NotInvocable
static_assert(std::is_same_v<decltype(std::ranges::views::enumerate), decltype(std::views::enumerate)>);
+struct MoveOnlyView : std::ranges::view_base {
+ constexpr explicit MoveOnlyView(int* b, int* e) : begin_(b), end_(e) {}
+ MoveOnlyView(const MoveOnlyView&) = delete;
+ MoveOnlyView& operator=(const MoveOnlyView&) = delete;
+ constexpr MoveOnlyView(MoveOnlyView&& other) : begin_(other.begin_), end_(other.end_) {
+ other.begin_ = nullptr;
+ other.end_ = nullptr;
+ }
----------------
frederick-vs-ja wrote:
Nitpick: Let's improve this move ctor with `exchange` and add conventional `noexcept` to it.
```suggestion
constexpr MoveOnlyView(MoveOnlyView&& other) noexcept
: begin_(std::exchange(other.begin_, nullptr)), end_(std::exchange(other.end_, nullptr)) {}
```
https://github.com/llvm/llvm-project/pull/197635
More information about the libcxx-commits
mailing list