[libcxx-commits] [PATCH] D107098: [libc++] Implement the underlying mechanism for range adaptors

Christopher Di Bella via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 17 10:31:57 PDT 2021


cjdb added a comment.

Will respond to other comments when I have the time to properly mull them over.



================
Comment at: libcxx/include/__ranges/range_adaptor.h:48
+_LIBCPP_HIDE_FROM_ABI
+constexpr auto operator|(_View&& __view, _Closure&& __closure)
+noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Closure>(__closure), _VSTD::forward<_View>(__view))))
----------------
ldionne wrote:
> cjdb wrote:
> > `a | b;` is always a bug for views and is pretty common, not only for folks who are just starting out, but also experienced users too.
> Isn't this valid?
> 
> ```
> std::vector<int> ints = {...};
> ints | views::transform([](int i) { std::cout << i; return i + 1; }); // intentionally discard the result
> ```
> 
> Someone using `transform` like that would never pass my code review, but it's valid and I think it's too bold to make that ill-formed.
Since all views are lazy by definition, that second line is a no-op.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D107098/new/

https://reviews.llvm.org/D107098



More information about the libcxx-commits mailing list