-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add a layer of operators that propagate nothingness #4
Comments
I can imagine at least three ways of doing this:
The second alternative, having a wrapper that provides arithmetic operators that propagate emptiness somehow, is the most appealing to me (mainly because these wrappers could work for all types implementing the EDIT: while maybe these operator wrappers could/should be prototyped here, and even included as part of Boost.Markable, maybe it would be worth it for them to be refactored in the future to a Boost.OptionalOperators library that ensures that they work with all "ranges of zero or one elements". |
Thank you for your interest in the library. I am sorry it took so long for me to reply. If I were to repeat your suggestion with my own words, it would go like this. My type |
I should have worded the request better to make it clear that this was not the case (since as you said, this is not doable in C++14, nor C++17, nor will be for the time being until we get reflection or What are your use cases for Currently I just maintain my own private fork of the library where I add the operators (with The resulting code is very nice because I don't need to deal with propagating the null value every time I use an operator. I just do that once for the type and then the propagation behavior is abstracted away. Just compare it yourself: // currently:
auto c = a && b?
a.value() + b.value()
: assert(false); // replace with throw, terminate, b, ...
// vs
auto c = a + b; // null value handling is part of the types, happens implicitly
// imagine doing with explicit null value handling:
auto d = a + b + c; Some times you need to do a different null value handling, or want to throw it in the face of the user, but at least in the code I write most of the time the exact type of null value handling doesn't matter. |
Ok, I can see the direction you want to go. I think it is incompatible with the design criteria of this library: to make every intention of the user explicit, so that a |
It would be nice to easily have a way to:
operator+
ifT
models RandomAccessIncrementable).I ended up adding all operators if T support them to my fork of compact optional, and asserting on emptiness by default, but different users might want different behavior here.
The text was updated successfully, but these errors were encountered: