Skip to content
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

Switch case "lifts" #12

Open
rolandschulz opened this issue Feb 4, 2019 · 2 comments
Open

Switch case "lifts" #12

rolandschulz opened this issue Feb 4, 2019 · 2 comments

Comments

@rolandschulz
Copy link

The README mentions it is TODO.

What's left to do and do you want any help implementing this? Note that mp11 has mp_with_index which does most of the work.

@quicknir
Copy link
Owner

quicknir commented Feb 8, 2019

Hey sorry it took me a while to respond. Implementation is straightforward, I would just generate it with the macros similar to the to_stuff. I actually considered implementing the to_string in terms of this construct but I think across different compilers I wasn't 100% convinced the assembly would be the same.

The real question is deciding on the interface. Most notably, what should happen when the enum passed in isn't actually any of the enumeration values (which is legal). One possibility is to have the user pass in two lambdas with the second taking no arguments and getting called in the case where no enum is found.

Any thoughts?

@rolandschulz
Copy link
Author

Sorry didn't notice your reply.

I would throw an exception. Out of range values should be exceptional so that wouldn't turn into misusing exception for control flow. I would consider this the most intuitive interface, because it is the simplest and follows what std::visit does. I would also add a function bool wise_enum::out_of_range<E>(v) (analogous to valueless_by_exception). That would let users check prior to the lift whether it'll succeed and avoid the possibility of an exception (e.g. if they compile with exceptions disabled).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants