r/cpp • u/Amazing-42 • Jun 14 '21
match(it): A light-weight header-only pattern-matching library for C++17.
https://github.com/BowenFu/matchit.cpp1
u/Amazing-42 Jul 03 '21
This page shows what Rust-style pattern matching examples would look like with the library in C++. https://github.com/BowenFu/matchit.cpp/blob/main/From-Rust-to-matchit.md
5
7
u/sphere991 Jun 15 '21
So is this just a copy of https://github.com/mpark/patterns or what?
8
6
Jun 15 '21
It seems it is. At least identifier names and usage of the first example is fully identical. It pretty strange to see so without additional explanations.
1
u/GunpowderGuy Oct 17 '21
Could this library be exported as a module since its public interface uses no macros?
1
22
u/rust_guy5 Jun 14 '21
I wrote this.
25
4
u/infectedapricot Jun 15 '21
Is this meant to be a Rust related joke or a serious claim? From previous posts, it looks like this is a troll account.
3
3
u/nablachez Jun 15 '21
Is there a reason why getclassname (about shape) is not constexpr like the others?
4
u/helloiamsomeone Jun 14 '21
I have used simple_match before and it's pretty cool.
Any reason why this requires C++17? Just convenience?
4
u/helloiamsomeone Jun 15 '21
Well, to answer myself: this one has a lot more features and the API lends itself better to code formatting (imo).
4
u/JohnZLi Jun 15 '21
Neat. The first example includes 3 headers for a simple factorial function. They really should be merged into 1.
2
2
3
u/InsanityBlossom Jun 15 '21
I'm sure it was fun to implement, and the skills required to build this is a no joke. But this concept is so alien to C++. The author was definitely inspired by Rust ;)
0
Jun 15 '21
[deleted]
1
u/Schnarfman Jun 15 '21
Point of order: Triple back ticks doesn’t get formatted properly for mobile. But if you use the other method - 4 leading spaces - everyone sees it properly
31
u/gracicot Jun 14 '21 edited Jun 14 '21
This is quite amazing what C++ can ship in a library, even though it's not perfect
and uses macros.