[libcxx-commits] [libcxx] [libc++][ranges] use `static operator()` for C++23 ranges (PR #86052)

Xiaoyang Liu via libcxx-commits libcxx-commits at lists.llvm.org
Thu Mar 21 13:35:58 PDT 2024


================
@@ -205,17 +205,19 @@ namespace views {
 namespace __chunk_by {
 struct __fn {
   template <class _Range, class _Pred>
-  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range, _Pred&& __pred) const
-      noexcept(noexcept(/**/ chunk_by_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))))
-          -> decltype(/*--*/ chunk_by_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))) {
-    return /*-------------*/ chunk_by_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred));
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto operator()(
+      _Range&& __range,
+      _Pred&& __pred) noexcept(noexcept(chunk_by_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))))
+      -> decltype(/*-----------------*/ chunk_by_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred))) {
+    return /*------------------------*/ chunk_by_view(std::forward<_Range>(__range), std::forward<_Pred>(__pred));
   }
 
   template <class _Pred>
     requires constructible_from<decay_t<_Pred>, _Pred>
-  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Pred&& __pred) const
-      noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
-    return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Pred>(__pred)));
+  _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI static constexpr auto
+  operator()(_Pred&& __pred) noexcept(is_nothrow_constructible_v<decay_t<_Pred>, _Pred>) {
+    constexpr auto __self = __fn{};
+    return __range_adaptor_closure_t(std::__bind_back(__self, std::forward<_Pred>(__pred)));
----------------
xiaoyang-sde wrote:

> I wonder whether we should change this place. We need a `*this` pointer so what is the benefit of this change?

This change allows the first overload of `operator()` to be `static`. We just need to figure out how to pass `__fn` to `std::__bind_back` here.

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


More information about the libcxx-commits mailing list