<functional>
: Fixes around not_fn
#4057
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Make the return type (
_Not_fn
) perfect forwarding call wrapper since C++20, which is a change in WG21-P0356R5.Currently this PR leaves
_Not_fn
as-is in C++17 mode, because the return type was nearly fully specified in C++17 (N4659 [func.not_fn]/1), which means thatoperator()
overloads, an invocation to a non-const value of the return type might select a const overload, anddecltype(!declval<invoke_result_t<...>>())
, if theoperator!
takes a non-movable return type ofstd::invoke(args...)
by value, the return type ofoperator()
would be ill-formed, while!std::invoke(args...)
being well-formed.In C++20 the first case should be ill-formed (in an SFINAE-friendly way), and the second case should be well-formed.
Also make
not_fn
reject non-move-constructible types. Fixes #4048.I don't know why call wrappers (except for
std::function
) are still required to be Cpp17MoveConstructible in C++17 and later. It seems that the restrictions can be lifted.