public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Simplify ranges::to closure objects
Date: Mon, 4 Dec 2023 12:28:54 +0000	[thread overview]
Message-ID: <CACb0b4=ZvPdLfhNq2-CC-c1xG8kGPiC29_2L1HDJ+BJOsgRquQ@mail.gmail.com> (raw)
In-Reply-To: <20231130192252.3123291-1-ppalka@redhat.com>

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	other threads:[~2023-12-04 12:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30 19:22 Patrick Palka
2023-12-04 12:28 ` Jonathan Wakely [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACb0b4=ZvPdLfhNq2-CC-c1xG8kGPiC29_2L1HDJ+BJOsgRquQ@mail.gmail.com' \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ppalka@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).