Skip to content

Use magic_enum for default enum value in help menu#32

Closed
vlovero wants to merge 1 commit intomorrisfranken:masterfrom
vlovero:patch-1
Closed

Use magic_enum for default enum value in help menu#32
vlovero wants to merge 1 commit intomorrisfranken:masterfrom
vlovero:patch-1

Conversation

@vlovero
Copy link
Copy Markdown

@vlovero vlovero commented Sep 19, 2025

Currently the default value for enum types gets displayed as an integer. magic_enum can be used to make the help print out a little more clear.

Currently the default value for enum types gets displayed as an integer. magic_enum can be used to make the help print out a little more clear.
@xerpi
Copy link
Copy Markdown
Contributor

xerpi commented Oct 24, 2025

This would be really helpful!

@xerpi
Copy link
Copy Markdown
Contributor

xerpi commented Oct 24, 2025

There's a warning:

[build] foo/build/debug/_deps/argparse-src/include/argparse/argparse.hpp:110:5: warning: control reaches end of non-void function [-Wreturn-type]
[build]   110 |     }
[build]       |     ^

The problem is that given

#ifdef HAS_MAGIC_ENUM
        } else if constexpr (std::is_enum<T>::value) {
            for (const auto &[name, value] : magic_enum::enum_entries<T>()) {
                if (v == name) {
                    return std::string{ value };
                }
            }
#endif
        } else if constexpr (has_ostream_operator<T>::value) {
            return static_cast<std::ostringstream &&>((std::ostringstream() << std::boolalpha << v)).str();       // https://github.com/stan-dev/math/issues/590#issuecomment-550122627
        } else {
            return "unknown";
        }

If (v == name) fails, then there's no return statement.
Maybe we should just move the return "unknown"; outside of the else.

@morrisfranken
Copy link
Copy Markdown
Owner

morrisfranken commented Oct 25, 2025

Hi @vlovero and @xerpi , thanks for the PR. Much appreciated! I've now merged this from pr #33

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.

3 participants