Show HN: Match(it): A C++17 pattern-matching library with lots of good stuffs
85 points| amazing42 | 3 years ago |github.com
Try it at https://godbolt.org/z/8YMr8Kz8j
85 points| amazing42 | 3 years ago |github.com
Try it at https://godbolt.org/z/8YMr8Kz8j
dymk|3 years ago
I hope I never see this in a production codebase, though!
On a kind of related note, I want to see an alternate history where C++ had support for Rust-ish proc macros, or Racket-ish macros. What would that language even look like? There'd probably be no need to hack existing C++ language semantics to add new features, you'd "just" generate the code that the meta-language lowers to.
Longhanks|3 years ago
Why? Looks completely readable, easy to understand to me.
Do you also hope to never see the STL in production? Because internally, that thing is high level unreadable C++.
gpderetta|3 years ago
olvy0|3 years ago
But MSVC latest instead generates the full runtime code and function call.
phoe-krk|3 years ago
Should this be reported anywhere?
fooker|3 years ago
amazing42|3 years ago
hkalbasi|3 years ago
amazing42|3 years ago
unknown|3 years ago
[deleted]
jokoon|3 years ago
Although if the C++ committee manages to add this without deprecating other things, I would be impressed.
corysama|3 years ago
synergy20|3 years ago
klyrs|3 years ago
[1] https://en.wikipedia.org/wiki/Pattern_matching
fouronnes3|3 years ago
amazing42|3 years ago
bhedgeoser|3 years ago
const fn factorial(n: u128) -> u128 { match n { 0 => 1, _ => n * factorial(n-1) } }
fn main() { dbg!(factorial(20)); }
amazing42|3 years ago
Rust does not support view pattern (called in Haskell) or app pattern (called in Racket). And that has been implemented in this library.
unknown|3 years ago
[deleted]
rowanG077|3 years ago
amazing42|3 years ago
unknown|3 years ago
[deleted]