]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Refactor bound arguments storage for bind_front/back
authorTomasz Kamiński <tkaminsk@redhat.com>
Tue, 19 Aug 2025 13:32:47 +0000 (15:32 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Tue, 26 Aug 2025 16:16:04 +0000 (18:16 +0200)
commit250dd5b5604fbc9149e30f6b9cfaabdd600592e7
tree8a8775fca6e771ee4ae201354fda8fc7ddfecb2a
parent36ab9b9c6747032bc6b4b3aae49202a7f30bf4c4
libstdc++: Refactor bound arguments storage for bind_front/back

This patch refactors the implementation of bind_front and bind_back to avoid
using std::tuple for argument storage. Instead, bound arguments are now:
* stored directly if there is only one,
* within a dedicated _Bound_arg_storage otherwise.

_Bound_arg_storage is less expensive to instantiate and access than std::tuple.
It can also be trivially copyable, as it doesn't require a non-trivial assignment
operator for reference types. Storing a single argument directly provides similar
benefits compared to both one element tuple or _Bound_arg_storage.

_Bound_arg_storage holds each argument in an _Indexed_bound_arg base object.
The base class is parameterized by both type and index to allow storing
multiple arguments of the same type. Invocations are handled by _S_apply_front
amd _S_apply_back static functions, which simulate explicit object parameters.
To facilitate this, the __like_t alias template is now unconditionally available
since C++11 in bits/move.h.

libstdc++-v3/ChangeLog:

* include/bits/move.h (std::__like_impl, std::__like_t): Make
available in c++11.
* include/std/functional (std::_Indexed_bound_arg)
(std::_Bound_arg_storage, std::__make_bound_args): Define.
(std::_Bind_front, std::_Bind_back): Use _Bound_arg_storage.
* testsuite/20_util/function_objects/bind_back/1.cc: Expand
test to cover cases of 0, 1, many bound args.
* testsuite/20_util/function_objects/bind_back/111327.cc: Likewise.
* testsuite/20_util/function_objects/bind_front/1.cc: Likewise.
* testsuite/20_util/function_objects/bind_front/111327.cc: Likewise.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/bits/move.h
libstdc++-v3/include/std/functional
libstdc++-v3/testsuite/20_util/function_objects/bind_back/1.cc
libstdc++-v3/testsuite/20_util/function_objects/bind_back/111327.cc
libstdc++-v3/testsuite/20_util/function_objects/bind_front/1.cc
libstdc++-v3/testsuite/20_util/function_objects/bind_front/111327.cc