Skip to content

Commit be309f0

Browse files
Merge pull request #33 from xerpi/magic_enum-default
Use magic_enum for default enum value in help menu
2 parents 58fcb68 + bf62c23 commit be309f0

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

include/argparse/argparse.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,19 @@ namespace argparse {
9393
#pragma GCC diagnostic pop
9494
#elif defined(_MSC_VER)
9595
#pragma warning(pop)
96+
#endif
97+
#ifdef HAS_MAGIC_ENUM
98+
} else if constexpr (std::is_enum<T>::value) {
99+
for (const auto &[name, value] : magic_enum::enum_entries<T>()) {
100+
if (v == name) {
101+
return std::string{ value };
102+
}
103+
}
96104
#endif
97105
} else if constexpr (has_ostream_operator<T>::value) {
98106
return static_cast<std::ostringstream &&>((std::ostringstream() << std::boolalpha << v)).str(); // https://github.com/stan-dev/math/issues/590#issuecomment-550122627
99-
} else {
100-
return "unknown";
101107
}
108+
return "unknown";
102109
}
103110

104111
std::vector<std::string> inline split(const std::string &str) {

0 commit comments

Comments
 (0)