From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 7B2613858D3C; Thu, 7 Dec 2023 21:36:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B2613858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701985013; bh=zToV4FzoP/FgKyK0fn2OoTizkAe+aoW/cXGhJrKbI1I=; h=From:To:Subject:Date:From; b=o7sEfq7iDqKMpb7dXCxEJNDZbUMntfxlorw6gT1lIhM7zKT1/64mGBoyesAt7iaX1 0+Ky+sOqaI9bjMY7WNcwgow7aYJhJt882UHmRPhsF8x2Sne4aIvi8hJR6hRWDNlTia o+gzBuEJ1nhoCek6UYCJry5b4P+4ORYmXpkbZatE= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-6294] libstdc++: Simplify ranges::to closure objects X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/master X-Git-Oldrev: cab0083dc72dfd22a1b2016b068f9313beb7f091 X-Git-Newrev: 0832cf42a6912f876086cb14b92f788d8406f393 Message-Id: <20231207213653.7B2613858D3C@sourceware.org> Date: Thu, 7 Dec 2023 21:36:53 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0832cf42a6912f876086cb14b92f788d8406f393 commit r14-6294-g0832cf42a6912f876086cb14b92f788d8406f393 Author: Patrick Palka Date: Thu Dec 7 16:36:23 2023 -0500 libstdc++: Simplify ranges::to closure objects We can use the existing _Partial range adaptor closure object for ranges::to instead of essentially reimplementing 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. Diff: --- libstdc++-v3/include/std/ranges | 128 ++++++++-------------------------------- 1 file changed, 26 insertions(+), 102 deletions(-) diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index afd0a38e0cf..fb9df3d3e79 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 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 requires __pipe_invocable constexpr auto @@ -9387,58 +9389,15 @@ namespace __detail /// @cond undocumented namespace __detail { - template - class _ToClosure - : public views::__adaptor::_RangeAdaptorClosure<_ToClosure<_Cont, _Args...>> + template + struct _To { - tuple...> _M_bound_args; - - public: - constexpr - _ToClosure(_Args&&... __args) - : _M_bound_args(std::forward<_Args>(__args)...) - { } - - // TODO: use explicit object functions ("deducing this"). - - template - constexpr auto - operator()(_Rg&& __r) & - { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, _M_bound_args); - } - - template - constexpr auto - operator()(_Rg&& __r) const & - { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, _M_bound_args); - } - - template + template constexpr auto - operator()(_Rg&& __r) && + operator()(_Range&& __r, _Args&&... __args) const { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, std::move(_M_bound_args)); - } - - template - constexpr auto - operator()(_Rg&& __r) const && - { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, std::move(_M_bound_args)); + return ranges::to<_Cont>(std::forward<_Range>(__r), + std::forward<_Args>(__args)...); } }; } // namespace __detail @@ -9461,65 +9420,26 @@ namespace __detail */ template 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 typename _Cont, typename... _Args> - class _ToClosure2 - : public views::__adaptor::_RangeAdaptorClosure<_ToClosure2<_Cont, _Args...>> + template typename _Cont> + struct _To2 { - tuple...> _M_bound_args; - - public: - constexpr - _ToClosure2(_Args&&... __args) - : _M_bound_args(std::forward<_Args>(__args)...) - { } - - // TODO: use explicit object functions ("deducing this"). - - template - constexpr auto - operator()(_Rg&& __r) & - { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, _M_bound_args); - } - - template - constexpr auto - operator()(_Rg&& __r) const & - { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, _M_bound_args); - } - - template - constexpr auto - operator()(_Rg&& __r) && - { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, std::move(_M_bound_args)); - } - - template + template constexpr auto - operator()(_Rg&& __r) const && + operator()(_Range&& __r, _Args&&... __args) const { - return std::apply([&__r](_Tp&&... __args) { - return ranges::to<_Cont>(std::forward<_Rg>(__r), - std::forward<_Tp>(__args)...); - }, std::move(_M_bound_args)); + return ranges::to<_Cont>(std::forward<_Range>(__r), + std::forward<_Args>(__args)...); } }; } // namespace __detail @@ -9543,9 +9463,13 @@ namespace __detail * `r | std::ranges::to(an_allocator)`. */ template 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