forked from BowenFu/matchit.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathat-Bindings.cpp
More file actions
32 lines (29 loc) · 757 Bytes
/
at-Bindings.cpp
File metadata and controls
32 lines (29 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "matchit.h"
#include <iostream>
using namespace matchit;
struct Hello
{
int32_t id;
};
using Message = std::variant<Hello>;
int32_t main()
{
Message const msg = Hello{5};
using namespace matchit;
auto const asHelloDs = asDsVia<Hello>(&Hello::id);
Id<int32_t> id_variable;
match(msg)(
pattern | asHelloDs(id_variable.at(3 <= _ && _ <= 7)) =
[&]
{
std::cout << "Found an id in range: " << *id_variable << std::endl;
},
pattern | asHelloDs(10 <= _ && _ <= 12) =
[&]
{ std::cout << "Found an id in another range" << std::endl; },
pattern | asHelloDs(id_variable) =
[&]
{
std::cout << "Found some other id: " << *id_variable << std::endl;
});
}