Skip to content

Support no default value enum_switch #199

@Sarna555

Description

@Sarna555

would it be possible to support enum_switch the way that we're used to use overload pattern with std::visit?
e.g

return magic_enum::enum_switch( overloaded{
           []( my_enum::val1 arg ) -> int { /* handle val1 enum */ return 1; },
           []( auto arg ) -> int { /* handle the rest */ throw notimplemented; /* or just return sth */ }
});

instead of

return magic_enum::enum_switch( overloaded{
           []( my_enum::val1 arg ) -> int { /* handle val1 enum */ return 1; },
           []( auto arg ) -> int { /* handle the rest */ throw notimplemented; /* or just return sth */ }
}, /*redundant default*/ int(2));

// or probably worse

auto r = magic_enum::enum_switch(
           []( my_enum::val1 arg ) -> int { /* handle val1 enum */ return 1; }
           , int(2)
);

if( r == 2 ) throw notimplemented;

I think forcing adding default Result produces boilerplate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions