ericniebler / range-v3

Range library for C++14/17/20, basis for C++20's std::ranges
Other
4.05k stars 437 forks source link

C++23's range_adaptor_closure equivalent #1804

Closed stripe2933 closed 6 months ago

stripe2933 commented 6 months ago

Hello, is there any equivalent for C++23's range_adaptor_closure? It would be good to make user defined class inherits its CTRP parent so that reduce boilerplate for operator|.

brevzin commented 6 months ago

range-v3 has one, it just looks a little different. You can see the description in the paper.

Basically you write:

namespace ranges::views {
  struct join_view_fn {
    template <viewable_range R>
        requires /* ... */
    constexpr auto operator(R&& r)
        -> join_view<all_t<R>>;
  };

  // for user consumption
  inline constexpr view_closure<join_view_fn> join{};
}

instead of:

namespace ranges::views {
  struct join_view_fn : range_adaptor_closure<join_view_fn> {
    template <viewable_range R>
        requires /* ... */
    constexpr auto operator(R&& r)
        -> join_view<all_t<R>>;
  };

  // for user consumption
  inline constexpr join_view_fn join{};
}
stripe2933 commented 6 months ago

Thank you for your answer.