-
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
[inplace_function] Opt-in "safe" default constructed inplace_function #166
Comments
I want to also comment on this issue because it is more far reaching than it initially appears. Not having a customization point for the default constructed Currently Say library Say library Then when library This is completely breaking behavior and forces libraries to literally copy paste code in order to get around this issue. The customization of A proposal is to add a policy to |
@liarokapisv: See "The space of design choices for Right now, if you call a default-constructed I think it's perfectly reasonable to argue that calling a default-constructed Do you have any particular use-case for calling |
I just want to say that I use this library on microcontroller-based embedded projects without exceptions... But I don't have a complex project structure with multiple
I'm +1 for this. |
One interesting use of the default constructor is callbacks with void return type. In those cases one may want to just ignore everything by default which reduces boilerplate on creation. One may want this to be undefined in which case they can I am admitedly more interested in allowing usage of If the purpose of If the purpose of If we accept that both the embedded usecase of not allowing exceptions is real and that it's also worth allowing users to define the behaviour of the default constructor in that case (I argue that it is useful since there is no catch-all error reporting approach in that case as is the case of exceptions) , then that's accepting that this is a real customization point of the library in which case I argue that a policy would be better suited to this task due to the multiple problems of the macro approach. Personally I don't mind banning the default constructor altogether in an embedded setting. What I have seen some libraries do is to check if exceptions are disabled and just declare but not define the relevant function leading to a linker error in case of misuse. It's then easy to build a wrapper on top of that that also allows for a default constructor. |
This would work for me as well! |
Banning the default constructor wouldn't solve the "narrow contract" issue: a moved-from object is in the same "disengaged" state as a default-constructed one.
Also, if we banned the default constructor then If |
A default constructed In the disengaged state there are again multiple approaches that one may take. But the whole discussion does not really have to do with either of these.
As such there are three choices that can be taken:
|
At the moment a default-constructed
inplace_function
is not safe to call (depending on SG14_INPLACE_FUNCTION_THROW). IMO it would be interesting to be able to opt-in to a behaviour where at leastinplace_function<void(...), ...>
can be safely used from default-constructed instances. Optionally (or a second opt-in?) whereinplace_function<R(...), ...>
returnsstd::declval<R>()
would potentially be interesting as well.The text was updated successfully, but these errors were encountered: