diff --git a/include/argparse/argparse.hpp b/include/argparse/argparse.hpp index d1bcbdd..7da3462 100644 --- a/include/argparse/argparse.hpp +++ b/include/argparse/argparse.hpp @@ -167,6 +167,13 @@ constexpr bool starts_with(std::basic_string_view prefix, return s.substr(0, prefix.size()) == prefix; } +enum class chars_format { + scientific = 0x1, + fixed = 0x2, + hex = 0x4, + general = fixed | scientific +}; + struct consume_hex_prefix_result { bool is_hexadecimal; std::string_view rest; @@ -258,46 +265,46 @@ template inline auto do_strtod(std::string const &s) -> T { } } -template struct parse_number { +template struct parse_number { auto operator()(std::string const &s) -> T { if (auto r = consume_hex_prefix(s); r.is_hexadecimal) throw std::invalid_argument{ - "std::chars_format::general does not parse hexfloat"}; + "chars_format::general does not parse hexfloat"}; return do_strtod(s); } }; -template struct parse_number { +template struct parse_number { auto operator()(std::string const &s) -> T { if (auto r = consume_hex_prefix(s); !r.is_hexadecimal) - throw std::invalid_argument{"std::chars_format::hex parses hexfloat"}; + throw std::invalid_argument{"chars_format::hex parses hexfloat"}; return do_strtod(s); } }; -template struct parse_number { +template struct parse_number { auto operator()(std::string const &s) -> T { if (auto r = consume_hex_prefix(s); r.is_hexadecimal) throw std::invalid_argument{ - "std::chars_format::scientific does not parse hexfloat"}; + "chars_format::scientific does not parse hexfloat"}; if (s.find_first_of("eE") == s.npos) throw std::invalid_argument{ - "std::chars_format::scientific requires exponent part"}; + "chars_format::scientific requires exponent part"}; return do_strtod(s); } }; -template struct parse_number { +template struct parse_number { auto operator()(std::string const &s) -> T { if (auto r = consume_hex_prefix(s); r.is_hexadecimal) throw std::invalid_argument{ - "std::chars_format::fixed does not parse hexfloat"}; + "chars_format::fixed does not parse hexfloat"}; if (s.find_first_of("eE") != s.npos) throw std::invalid_argument{ - "std::chars_format::fixed does not parse exponent part"}; + "chars_format::fixed does not parse exponent part"}; return do_strtod(s); } @@ -397,16 +404,16 @@ public: action(details::parse_number()); else if constexpr (is_one_of(Shape, 'a', 'A') && std::is_floating_point_v) - action(details::parse_number()); + action(details::parse_number()); else if constexpr (is_one_of(Shape, 'e', 'E') && std::is_floating_point_v) - action(details::parse_number()); + action(details::parse_number()); else if constexpr (is_one_of(Shape, 'f', 'F') && std::is_floating_point_v) - action(details::parse_number()); + action(details::parse_number()); else if constexpr (is_one_of(Shape, 'g', 'G') && std::is_floating_point_v) - action(details::parse_number()); + action(details::parse_number()); else static_assert(alignof(T) == 0, "No scan specification for T");