|
| 1 | +#include "matchit.h" |
| 2 | +#include <iostream> |
| 3 | + |
| 4 | +enum class OS_Type |
| 5 | +{ |
| 6 | + Linux, |
| 7 | + BSD |
| 8 | +}; |
| 9 | + |
| 10 | +enum class Arch_Type |
| 11 | +{ |
| 12 | + ARM64, |
| 13 | + X8664 |
| 14 | +}; |
| 15 | + |
| 16 | +int |
| 17 | +get_sample_write_syscode_code(OS_Type os_type, Arch_Type arch_type) |
| 18 | +{ |
| 19 | + namespace m = matchit; |
| 20 | + |
| 21 | + // Dependent enum case example: |
| 22 | + return m::match(os_type)( |
| 23 | + m::pattern | OS_Type::BSD = |
| 24 | + [&] { |
| 25 | + return m::match(arch_type)(m::pattern | Arch_Type::ARM64 = 1, |
| 26 | + m::pattern | Arch_Type::X8664 = 4, |
| 27 | + m::pattern | m::_ = 1); |
| 28 | + }, |
| 29 | + m::pattern | OS_Type::Linux = |
| 30 | + [&] { |
| 31 | + return m::match(arch_type)(m::pattern | Arch_Type::ARM64 = 2, |
| 32 | + m::pattern | Arch_Type::X8664 = 5, |
| 33 | + m::pattern | m::_ = 1); |
| 34 | + }, |
| 35 | + m::pattern | m::_ = 1); |
| 36 | +} |
| 37 | + |
| 38 | +int32_t |
| 39 | +main() |
| 40 | +{ |
| 41 | + // Independent enum case example: |
| 42 | + auto independent_sample = m::match(os_type, arch_type)( |
| 43 | + m::pattern | m::ds(OS_Type::Linux, Arch_Type::ARM64) = 2, |
| 44 | + m::pattern | m::ds(OS_Type::Linux, Arch_Type::X8664) = 5, |
| 45 | + m::pattern | m::ds(OS_Type::BSD, Arch_Type::X8664) = 4, |
| 46 | + m::pattern | m::_ = 1); |
| 47 | + |
| 48 | + std::cout << "independent write(3) enum case example: " << independent_sample |
| 49 | + << std::endl; |
| 50 | + |
| 51 | + std::cout << "dependent write(3) enum case example: " |
| 52 | + << get_sample_write_syscode_code(OS_Type::Linux, Arch_Type::ARM64) |
| 53 | + << std::endl; |
| 54 | +} |
0 commit comments