A language that I am working on has those things "built-in" (it still generates compilable C++ in the backend). I did recently add pattern matching (and not just on variants) where the above would be equivalent to:
(I have some ideas to allow named labels instead of numerical indices but that is not yet implemented)
It is, in spirit, an implementation of the inspect proposal [1], but with a (subjectively) much simpler and more powerful syntax (the grammar of the entire language is fully LALR(1) without ambiguities).
Comments
A language that I am working on has those things "built-in" (it still generates compilable C++ in the backend). I did recently add pattern matching (and not just on variants) where the above would be equivalent to:
If a type repeats in the same variant, you would match by index to tell them apart: (I have some ideas to allow named labels instead of numerical indices but that is not yet implemented)It is, in spirit, an implementation of the inspect proposal [1], but with a (subjectively) much simpler and more powerful syntax (the grammar of the entire language is fully LALR(1) without ambiguities).
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p137...