public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Patrick Palka <ppalka@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r14-7219] libstdc++: Use C++23 deducing this in std::bind_front Date: Sat, 13 Jan 2024 04:02:45 +0000 (GMT) [thread overview] Message-ID: <20240113040246.0906C3858D32@sourceware.org> (raw) https://gcc.gnu.org/g:3e1ffa7dd111374a5e277b71269f9b6e10b3ec57 commit r14-7219-g3e1ffa7dd111374a5e277b71269f9b6e10b3ec57 Author: Patrick Palka <ppalka@redhat.com> Date: Fri Jan 12 22:55:43 2024 -0500 libstdc++: Use C++23 deducing this in std::bind_front This simplifies the operator() of _Bind_front using C++23 deducing this, allowing us to condense multiple operator() overloads into one. In passing I think we can remove _Bind_front's defaulted special member declarations and just let the compiler implicitly generate them for us. libstdc++-v3/ChangeLog: * include/std/functional (_Bind_front): Remove =default special member function declarations. (_Bind_front::operator()): Implement using C++23 deducing this when available. * testsuite/20_util/function_objects/bind_front/111327.cc: Adjust testcase to expect better errors in C++23 mode. Diff: --- libstdc++-v3/include/std/functional | 19 +++++++++++++------ .../20_util/function_objects/bind_front/111327.cc | 14 ++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 8d50a730889..fcfd2df7957 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -934,12 +934,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_bound_args(std::forward<_Args>(__args)...) { static_assert(sizeof...(_Args) == sizeof...(_BoundArgs)); } - _Bind_front(const _Bind_front&) = default; - _Bind_front(_Bind_front&&) = default; - _Bind_front& operator=(const _Bind_front&) = default; - _Bind_front& operator=(_Bind_front&&) = default; - ~_Bind_front() = default; - +#if __cpp_explicit_this_parameter + template<typename _Self, typename... _CallArgs> + constexpr + invoke_result_t<__like_t<_Self, _Fd>, __like_t<_Self, _BoundArgs>..., _CallArgs...> + operator()(this _Self&& __self, _CallArgs&&... __call_args) + noexcept(is_nothrow_invocable_v<__like_t<_Self, _Fd>, + __like_t<_Self, _BoundArgs>..., _CallArgs...>) + { + return _S_call(std::forward<_Self>(__self), _BoundIndices(), + std::forward<_CallArgs>(__call_args)...); + } +#else template<typename... _CallArgs> requires true constexpr @@ -997,6 +1003,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename... _CallArgs> void operator()(_CallArgs&&...) const && = delete; +#endif private: using _BoundIndices = index_sequence_for<_BoundArgs...>; diff --git a/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc index 43b56ca4378..5fe0a83baec 100644 --- a/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc +++ b/libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc @@ -17,24 +17,26 @@ struct G { int main() { auto f0 = std::bind_front(F{}); - f0(); // { dg-error "deleted" } + f0(); // { dg-error "deleted|no match" } std::move(f0)(); std::as_const(f0)(); std::move(std::as_const(f0))(); auto g0 = std::bind_front(G{}); - g0(); // { dg-error "deleted" } - std::move(g0)(); // { dg-error "deleted" } + g0(); // { dg-error "deleted|no match" } + std::move(g0)(); // { dg-error "deleted|no match" } std::move(std::as_const(g0))(); auto f1 = std::bind_front(F{}, 42); - f1(); // { dg-error "deleted" } + f1(); // { dg-error "deleted|no match" } std::move(f1)(); std::as_const(f1)(); std::move(std::as_const(f1))(); auto g1 = std::bind_front(G{}, 42); - g1(); // { dg-error "deleted" } - std::move(g1)(); // { dg-error "deleted" } + g1(); // { dg-error "deleted|no match" } + std::move(g1)(); // { dg-error "deleted|no match" } std::move(std::as_const(g1))(); } + +// { dg-error "no type named 'type' in 'struct std::invoke_result" "" { target c++23 } 0 }
reply other threads:[~2024-01-13 4:02 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20240113040246.0906C3858D32@sourceware.org \ --to=ppalka@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /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: linkBe 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).