On Thu, 30 Nov 2023 at 19:23, Patrick Palka wrote:
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?

OK, thanks for simplifying it.

>
> -- >8 --
>
> Use the existing _Partial range adaptor closure object in the
> definition of ranges::to instead of essentially open coding it.
>
> libstdc++-v3/ChangeLog:
>
>         * include/std/ranges (__detail::_ToClosure): Replace with ...
>         (__detail::_To): ... this.
>         (__detail::_ToClosure2): Replace with ...
>         (__detail::To2): ... this.
>         (to): Simplify using the existing _Partial range adaptor
>         closure object.
> ---
>  libstdc++-v3/include/std/ranges | 140 ++++++++------------------------
>  1 file changed, 32 insertions(+), 108 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
> index 9d4c2e01c4d..33e576e563a 100644
> --- a/libstdc++-v3/include/std/ranges
> +++ b/libstdc++-v3/include/std/ranges
> @@ -1007,6 +1007,7 @@ namespace views::__adaptor
>
>        // Invoke _Adaptor with arguments __r, _M_args... according to the
>        // value category of this _Partial object.
> +      // TODO: use explicit object functions ("deducing this").
>        template<typename _Range>
>         requires __adaptor_invocable<_Adaptor, _Range, const _Args&...>
>         constexpr auto
> @@ -1137,6 +1138,7 @@ namespace views::__adaptor
>
>        // Invoke _M_rhs(_M_lhs(__r)) according to the value category of this
>        // range adaptor closure object.
> +      // TODO: use explicit object functions ("deducing this").
>        template<typename _Range>
>         requires __pipe_invocable<const _Lhs&, const _Rhs&, _Range>
>         constexpr auto
> @@ -9391,59 +9393,16 @@ namespace __detail
>  /// @cond undocumented
>  namespace __detail
>  {
> -  template<typename _Cont, typename... _Args>
> -    class _ToClosure
> -    : public views::__adaptor::_RangeAdaptorClosure<_ToClosure<_Cont, 
> _Args...>>
> +  template<typename _Cont>
> +    struct _To
>      {
> -      tuple<decay_t<_Args>...> _M_bound_args;
> -
> -    public:
> -      constexpr
> -      _ToClosure(_Args&&... __args)
> -      : _M_bound_args(std::forward<_Args>(__args)...)
> -      { }
> -
> -      // TODO: use explicit object functions ("deducing this").
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) &
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, _M_bound_args);
> -       }
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) const &
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, _M_bound_args);
> -       }
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) &&
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, std::move(_M_bound_args));
> -       }
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) const &&
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, std::move(_M_bound_args));
> -       }
> +      template<typename _Range, typename... _Args>
> +      constexpr auto
> +      operator()(_Range&& __r, _Args&&... __args) const
> +      {
> +       return ranges::to<_Cont>(std::forward<_Range>(__r),
> +                                std::forward<_Args>(__args)...);
> +      }
>      };
>  } // namespace __detail
>  /// @endcond
> @@ -9465,66 +9424,27 @@ namespace __detail
>     */
>    template<typename _Cont, typename... _Args>
>      requires (!view<_Cont>)
> -    constexpr __detail::_ToClosure<_Cont, _Args...>
> +    constexpr auto
>      to [[nodiscard]] (_Args&&... __args)
> -    { return {std::forward<_Args>(__args)...}; }
> +    {
> +      using __detail::_To;
> +      using views::__adaptor::_Partial;
> +      return _Partial<_To<_Cont>, 
> decay_t<_Args>...>{std::forward<_Args>(__args)...};
> +    }
>
>  /// @cond undocumented
>  namespace __detail
>  {
> -  template<template<typename...> typename _Cont, typename... _Args>
> -    class _ToClosure2
> -    : public views::__adaptor::_RangeAdaptorClosure<_ToClosure2<_Cont, 
> _Args...>>
> +  template<template<typename...> typename _Cont>
> +    struct _To2
>      {
> -      tuple<decay_t<_Args>...> _M_bound_args;
> -
> -    public:
> -      constexpr
> -      _ToClosure2(_Args&&... __args)
> -      : _M_bound_args(std::forward<_Args>(__args)...)
> -      { }
> -
> -      // TODO: use explicit object functions ("deducing this").
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) &
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, _M_bound_args);
> -       }
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) const &
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, _M_bound_args);
> -       }
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) &&
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, std::move(_M_bound_args));
> -       }
> -
> -      template<typename _Rg>
> -       constexpr auto
> -       operator()(_Rg&& __r) const &&
> -       {
> -         return std::apply([&__r]<typename... _Tp>(_Tp&&... __args) {
> -           return ranges::to<_Cont>(std::forward<_Rg>(__r),
> -                                    std::forward<_Tp>(__args)...);
> -         }, std::move(_M_bound_args));
> -       }
> +      template<typename _Range, typename... _Args>
> +      constexpr auto
> +      operator()(_Range&& __r, _Args&&... __args) const
> +      {
> +       return ranges::to<_Cont>(std::forward<_Range>(__r),
> +                                std::forward<_Args>(__args)...);
> +      }
>      };
>  } // namespace __detail
>  /// @endcond
> @@ -9547,9 +9467,13 @@ namespace __detail
>     * `r | std::ranges::to<std::vector>(an_allocator)`.
>     */
>    template<template<typename...> typename _Cont, typename... _Args>
> -    constexpr __detail::_ToClosure2<_Cont, _Args...>
> +    constexpr auto
>      to [[nodiscard]] (_Args&&... __args)
> -    { return {std::forward<_Args>(__args)...}; }
> +    {
> +      using __detail::_To2;
> +      using views::__adaptor::_Partial;
> +      return _Partial<_To2<_Cont>, 
> decay_t<_Args>...>{std::forward<_Args>(__args)...};
> +    }
>
>  } // namespace ranges
>  #endif // __cpp_lib_ranges_to_container
> --
> 2.43.0.rc1
>

Reply via email to