Skip to content

Conversation

@jahan-addison
Copy link
Contributor

I could not find an enum class and nested enum example to replace a nested switch case on enums. matchit was very helpful in enumerating complicated nested cases

@BowenFu
Copy link
Owner

BowenFu commented Dec 31, 2025

@jahan-addison Thanks for adding the sample. Regarding nested example, there could be two cases, 1) both values are independent, 2) the second value is dependent on how the first one is matched.

For the first case, the codes could be more concise like

return m::match(os_type, arch_type)(
    m::pattern | m:: ds(OS_Type:: Linux, Arch_Type::ARM64) = 2,
    m::pattern | m::ds(OS_Type:: Linux, Arch_Type:: X8664) = 5,
    m::pattern | m::ds(OS_Type::BSD, Arch_Type:: X8664) = 4,
    m::pattern | m::_ = 1);

For the second case, the nested version could be more valuable.

@jahan-addison
Copy link
Contributor Author

Nice, I'll add both; in my case the values were dependent, but independent is another use case too

@BowenFu BowenFu merged commit 111a228 into BowenFu:main Dec 31, 2025
5 of 12 checks passed
@BowenFu
Copy link
Owner

BowenFu commented Dec 31, 2025

Thank you Jahan. I just merged it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants