[committed] libstdc++: Avoid a move in std::function construction (LWG 2447)

Jonathan Wakely jwakely@redhat.com
Sat Aug 28 12:14:54 GMT 2021


On 27/08/21 00:13 +0100, Jonathan Wakely wrote:
>This makes the std::function constructor use perfect forwarding, to
>avoid an unnecessary move-construction of the target. This means we need
>to rewrite the _Function_base::_Base_manager::_M_init_functor function
>to use a forwarding reference, and so can reuse it for the clone
>operation.
>
>Also simplify the SFINAE constraints on the constructor, by combining
>the !is_same_v<remove_cvref_t<F>, function> constraint into the
>_Callable trait.
>
>Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
>
>libstdc++-v3/ChangeLog:
>
>	* include/bits/std_function.h (_function_base::_Base_manager):
>	Replace _M_init_functor with a function template using a
>	forwarding reference, and a pair of _M_create function
>	templates. Reuse _M_create for the clone operation.
>	(function::_Decay_t): New alias template.
>	(function::_Callable): Simplify by using _Decay.
>	(function::function(F)): Change parameter to forwarding
>	reference, as per LWG 2447. Add noexcept-specifier. Simplify
>	constraints.
>	(function::operator=(F&&)): Add noexcept-specifier.
>	* testsuite/20_util/function/cons/lwg2774.cc: New test.
>	* testsuite/20_util/function/cons/noexcept.cc: New test.
>

This makes the new static_asserts give a slightly nicer error message
that doesn't involve <template-parameter-2-2>.

Tested powerpc64le-linux. Committed to trunk.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch.txt
Type: text/x-patch
Size: 4604 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210828/0a0f47fa/attachment.bin>


More information about the Gcc-patches mailing list