[libcxx-commits] [libcxx] WIP [libc++][ranges] Applied [[nodiscard]] to `transform_view` (PR #204014)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 17 03:20:18 PDT 2026


frederick-vs-ja wrote:

> > In order to test all functions marked [[nodiscard]], we should use some non-common and non-simple range (i.e. whose non-const and const versions of begin and end functions have four different return types).
> 
> Could you please give me an example on how this could work?

I think we can use the following:
```C++
struct TestView : std::ranges::view_interface<TestView> {
  int* begin();
  char* begin() const;
  const int* end();
  const char* end() const;
};
```

Then `TestView{} | views::transform(std::identity{})` should result the `transform_view` suitable for tests. (For `std::identity` you should include `<functional>`.)

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


More information about the libcxx-commits mailing list