-
Notifications
You must be signed in to change notification settings - Fork 52
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
What is the state of a moved-from inplace_function? #113
Comments
Interesting, I'll take a closer look at Folly. So this would mean we don't throw upon a call to an unset inplace function? This is not how std::function works, but maybe that's okay. |
Incorrect. I like the throwing behavior (although there are definitely people who think that throwing on a logic error is not useful and would rather UB in that case). This is about whether a moved-from function should become "empty" (Folly, fu2) or become "unspecified/invalid/UB" (inplace_function).
You're correct that |
Ah I see, thanks, and agreed. I'm happy to keep the throw on calling an unset fn, and UB for calling a moved-from fn. I don't mind this being UB (at least until someone protests about this big time) |
Hmm, I forget why I closed this via 56feddf; that commit doesn't look relevant! This std-proposals thread got me thinking: If we allow "move-from" to actually make the source object empty, instead of putting it into the moved-from state, then we can express So I think there will be a big advantage to making moved-from |
Fixes WG21-SG14#113 for real.
Both
folly::Function
andfu2::function
, as far as I can tell, make the following test case pass:To make this test case fail, you have to leave
foo
in a sort of "partly moved from" state, where callingfoo()
effectively has undefined behavior (because the containedSomeFunctor
object you're calling is in a moved-from state), which kind of defeats the purpose of having an "empty" (bad_function_call
-throwing) state at all.On the other hand, if you do make this test case pass, then you end up with a strongly type-safe object type, where the object is fundamentally not allowed to enter a "nonsense" or "partly-moved-from" state. This strikes me as a good idea. I think
inplace_function
should follow the example of Folly here, and make this test case pass.The text was updated successfully, but these errors were encountered: