-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Remove 'Empty' state from 'Event', rely on 'optional' #2992
base: master
Are you sure you want to change the base?
Conversation
I considered this in the past and decided I didn’t like it because it requires excessive |
Here's my branch from back in November. I looked at this and didn't think it was worth doing. To avoid lots of |
Pull Request Test Coverage Report for Build 9066610392Details
💛 - Coveralls |
What are the advantages of this over std::monostate? |
Monostate is just another symbol for ab empty state, which is a state a valid event should never be in. As @ChrisThrasher mentioned in his PR, event shouldn't even have an empty state and most importantly such a state should not be public and accessible to users. The reason why we had an empty state to begin with is because some APIa such as pollEvent need to return immediately and tell the user that no event was polled. In C++17 we have an idiomatic way of expressing the possible absence of a result: optional. We are using that throughout the library already and using it for events solves the "public empty state but not really" issue and, even better, makes event a type that's always guaranteed to be valid and non empty. |
@ChrisThrasher Can you explain the rationale behind this? What is wrong with |
It's a meaningless implementation detail. Operating systems or windowing systems do not produce empty events. We simply needed a sentinel to signal "hey, you tried to poll events but nothing was available" in user loops. |
d9de771
to
2953f26
Compare
Proof of concept right now as I don't have access to a compiler, but I think this is a superior design compared to #2991.
Removing the empty state from event results in a much more type-safe API. Events cannot be default-constructed anymore, and APIs that poll events now return an optional event, making it clear that an empty state can be present without polluting usages of events that cannot be in such an empty state.
@ChrisThrasher: feel free to continue working on this branch to adjust the usages of event in tests and examples.