Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/georgiifirsov/patternmatching
Short header-only library that allows you to use pattern matching in C++. Written in pure standard C++14.
https://github.com/georgiifirsov/patternmatching
cplusplus cplusplus-14 cpp cpp14 functional-programming pattern-matching templates
Last synced: 10 days ago
JSON representation
Short header-only library that allows you to use pattern matching in C++. Written in pure standard C++14.
- Host: GitHub
- URL: https://github.com/georgiifirsov/patternmatching
- Owner: GeorgiiFirsov
- License: gpl-3.0
- Created: 2020-02-25T21:43:12.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-03-11T20:48:48.000Z (over 4 years ago)
- Last Synced: 2024-08-10T04:23:17.593Z (3 months ago)
- Topics: cplusplus, cplusplus-14, cpp, cpp14, functional-programming, pattern-matching, templates
- Language: C++
- Homepage: https://georgyfirsov.github.io/src/cpp_pattern_matching.html
- Size: 36.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PatternMatching
**Motivation:** there's no pattern matching in C++, but sometimes it can make your code
more clean, than without it. Consider this example:```cpp
//
// You need to call Java fucntion from C++.
// Usually you do this way:
//int JavaCallHelper(int elem)
{
return jni->CallIntFunction( elem );
}float JavaCallHelper(float elem)
{
return jni->CallFloatFunction( elem );
}template
auto JavaCall(_Type elem)
{
return JavaCallHelper(elem);
}
```With pattern matching you can do such beautiful thing:
```cpp
template
auto JavaCall(_Type elem)
{
// Elements are passed as tuple in order
// to support multiple arguments
return match::Match(
std::make_tuple( elem ),
[](int elem) { return jni->CallIntFunction( elem ); },
[](float elem) { return jni->CallFloatFunction( elem ); }
);
}
```### Advantages
- Header only library
- C++14 supported
- Dispatch is a compile-time process => no runtime delay