-
Notifications
You must be signed in to change notification settings - Fork 70
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
Requesting tuple_match_apply #55
Comments
This is how I'd have written it: https://godbolt.org/z/dn7hhh It's a bit less clear than ideal because values can't be put directly into a type list, they have to be wrapped into |
@pdimov brainbending, but amazing... I could not understand how you can use E(value, not type) as template parameter, but it is of integral_constant kind of thing so that is why (I guess) it works. https://godbolt.org/z/r8PxaM Is there a reason why there is no mp_enum? Regarding this issue: your solution is very nice, but you might want to keep it open with lowest priority in case you got some other people in the future asking for this or similar feature. I say this since original code is potentially less efficient but probably a bit more readable to average C++ developer... Anyways thank you for a quick and great answer, and thanks to Barry for spreading awareness of mp11 on SO. |
I could have used Under C++17, I can in principle define |
@pdimov I was assuming mp_enum could "remember" the enum class it "came from"(using enum_type = ....) while behaving mostly like integral_constant, but then when "assignments" happen from another mp_enum you would check that enum_type matches so you can not convert enum class Color(with integral value 47) to enum class SIUnit. But again hard for me to claim this is desired since I do not have overview of the library/common use cases. |
First sorry for the ugly name, I could not think of anything better.
I know mp11 is mostly a lib for nice manipulation of lists, but one feature that really worked great for me is the tuple_for_each.
I used it to implement nice(IMHO) dispatching on runtime value. "Problem" is that it is not optimally efficient since I am doing an equivalent of many ifs, instead of a switch or if else.
Code example with basic idea is here(code is missing propagation of return value of the lambda, ignores alignment... but I hope general idea is clear).
https://godbolt.org/z/1TscGs
I have no idea what is the proper way to handle default case, I would suspect that there could be a tag type, but in my use I do not really need it since I cover all cases, so hard for me to judge if it would be a good addition.
The text was updated successfully, but these errors were encountered: