2 ms·
There has been a proposal to add pattern matching to C++ for nearly a decade now https://www.stroustrup.com/OpenPatternMatching.pdf https://www.stroustrup.com/O
by corysama 4y ago
There has been a proposal to add pattern matching to C++ for nearly a decade now https://www.stroustrup.com/OpenPatternMatching.pdf https://www.stroustrup.com/OpenPatternMatching.pdf Shame it never got in. With language support for matching, sum types and product types it would be a completely different language.
- UncleOxidant 4y agoWouldn't it be very similar to Rust? (or OCaml - but without the automatic memory management)
- amazing42 4y agoActually this library (match(it)) is more similar to Racket. You can see there are lots of patterns borrowed from Racket pattern matching, say app pattern and ooo pattern.
- pclmulqdq 4y agoThe regex library in the STL was quite a lesson for the C++ maintainers. They will probably not allow anything similar any time soon.
- tialaramex 4y agoAlthough the phrase "pattern matching" is involved these are completely different features. Also, unlike for regular expressions what you actually want here is typically a language feature, even if a bunch of the lifting is done in your standard library. In particular you probably want a keyword (or in several C++ pattern matching proposals, more than one) and new behaviour not just a few functions and constants. You could think of this as a bit like "switch" but on the other hand if your insight into switch is that it's basically a computed go-to wearing fancy dress then no, not that, the thing ordinary people use switch for.