3 ms·
std::visit mostly allows you to do that already: https://coliru.stacked-crooked.com/a/be5c44281eea8bc4 https://coliru.stacked-crooked.com/a/be5c44281eea8bc4 T
by Chabs 8y ago
std::visit mostly allows you to do that already:
https://coliru.stacked-crooked.com/a/be5c44281eea8bc4 https://coliru.stacked-crooked.com/a/be5c44281eea8bc4
Then only unfortunate missing piece of the puzzle is that there's no trivial way to create a closure out of this, so it requires a bit more manual work to propagate local state to the visitor.
- ddalcino 8y agoIf you build your visitor out of lambdas, instead of a struct, you can propagate local state to the visitor easily by using lambda captures. There are good examples of this approach at https://en.cppreference.com/w/cpp/utility/variant/visit https://en.cppreference.com/w/cpp/utility/variant/visit
- Chabs 8y agoUnfortunately, you can't leverage template substitution rules with the lambda approach. And that's really necessary if you want to have actual powerful match expressions.
- pjmlp 8y agoFor those working with C++ an answer might come in C++23. http://open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1371r0.pdf http://open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1371r0....