-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<functional>
: Fixes around not_fn
#4057
<functional>
: Fixes around not_fn
#4057
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.
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?
} |
That wouldn't "avoid hard errors", it would transform a hard error into a different hard error. |
Thanks - this compile-time change is low-risk enough that I think we need only one maintainer approval. |
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for noticing and fixing this issue in |
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.