C++ match expressions would make std::variant a really nice alternative.
I assume there is already a proposal out?
I assume there is already a proposal out?
// Client visitor code
match(
thingy,
[](const PurpleThingy& ) {std::cout << "purple thingy\n";},
[](const LittleThingy& ) {std::cout << "little thingy\n";},
[](const auto& ) {std::cout << "any other type\n";}
);
Working example:
https://coliru.stacked-crooked.com/a/dfed39bc7fcdfb01https://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.
http://open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1371r0....