[Bug libstdc++/122032] The size of bind_front/bind_back<fn>(...) is not optimized
cvs-commit at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Nov 14 12:04:37 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122032
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tomasz Kaminski <tkaminsk@gcc.gnu.org>:
https://gcc.gnu.org/g:71004c2414337bd781e1221acbcca2031bb6b614
commit r16-5276-g71004c2414337bd781e1221acbcca2031bb6b614
Author: Tomasz KamiÅski <tkaminsk@redhat.com>
Date: Fri Oct 24 10:24:26 2025 +0200
libstdc++: Use _Bind_front_t/_Bind_back_t in bind_front<f>/bind_back<f>
[PR122032]
This patch changes the implementation of bind_front<f> and bind_back<f> to
return a _Bind_front_t<_Bind_fn_t<f>, ...> and _Bind_back_t<_Bind_fn_t<f>,
...>
respectively, replacing the previous lambda-based implementation. The prior
use
of a lambda caused non-conforming behavior with respect to C++23
[func.require]
p8, which requires that bind_front<f>(s), bind_front<f>(move(s)), and
bind_front<f>(as_const(s)) produce the same type.
Additionally, using specialized structs reduces the size of the resulting
functor
in certain scenarios (see PR).
For the zero-argument case, the function still returns a _Bind_fn_t<f>.
Since this
type is already a perfect forwarding call wrapper, it yields the same
result as
_Bind_front_t<_Bind_fn_t<f>>.
A consequence of this change is that the types returned by
bind_front<f>(args...)
and bind_back<f>(args...) are no longer structural - they are not required
to be
structural by the standard.
PR libstdc++/122032
libstdc++-v3/ChangeLog:
* include/std/functional (std::bind_front<f>, std::bind_back<f>):
Define in terms of _Bind_front_t/_Bind_back_t.
* testsuite/20_util/function_objects/bind_back/nttp.cc: New tests.
* testsuite/20_util/function_objects/bind_front/nttp.cc: New tests.
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz KamiÅski <tkaminsk@redhat.com>
More information about the Gcc-bugs
mailing list