<functional>: Fixes around not_fn#4057
Merged
StephanTLavavej merged 2 commits intomicrosoft:mainfrom Oct 4, 2023
Merged
Conversation
1. Make the return type (`_Not_fn`) perfect forwarding call wrapper since C++20, which is a change in WG21-P0356R5. 2. Make `not_fn` reject non-move-constructible types.
Contributor
|
You should probably also add a struct OnlyMovableFun {
OnlyMovableFun() = default;
OnlyMovableFun(const OnlyMovableFun&) = delete;
OnlyMovableFun(OnlyMovableFun&&) = default;
bool operator()(auto) const;
};
int main() {
OnlyMovableFun f;
auto nf = std::not_fn(f); // should be static_assert?
} |
Contributor
That wouldn't "avoid hard errors", it would transform a hard error into a different hard error. |
StephanTLavavej
approved these changes
Oct 3, 2023
Member
|
Thanks - this compile-time change is low-risk enough that I think we need only one maintainer approval. |
Member
|
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Member
|
Thanks for noticing and fixing this issue in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_fnas-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_fnreject 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.