Commit df229cff0d5b96e146f3f11441f714e8e240cad0
1 parent
a20bda61
Fix integer parsing to be more general
Fixes #277. Makes integer parsing to be more general and allow whatever types the user actually uses instead of hard coding a set of integers.
Showing
1 changed file
with
8 additions
and
54 deletions
include/cxxopts.hpp
| ... | ... | @@ -925,60 +925,12 @@ namespace cxxopts |
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | - inline | |
| 929 | - void | |
| 930 | - parse_value(const std::string& text, uint8_t& value) | |
| 931 | - { | |
| 932 | - integer_parser(text, value); | |
| 933 | - } | |
| 934 | - | |
| 935 | - inline | |
| 936 | - void | |
| 937 | - parse_value(const std::string& text, int8_t& value) | |
| 938 | - { | |
| 939 | - integer_parser(text, value); | |
| 940 | - } | |
| 941 | - | |
| 942 | - inline | |
| 943 | - void | |
| 944 | - parse_value(const std::string& text, uint16_t& value) | |
| 945 | - { | |
| 946 | - integer_parser(text, value); | |
| 947 | - } | |
| 948 | - | |
| 949 | - inline | |
| 950 | - void | |
| 951 | - parse_value(const std::string& text, int16_t& value) | |
| 952 | - { | |
| 953 | - integer_parser(text, value); | |
| 954 | - } | |
| 955 | - | |
| 956 | - inline | |
| 957 | - void | |
| 958 | - parse_value(const std::string& text, uint32_t& value) | |
| 959 | - { | |
| 960 | - integer_parser(text, value); | |
| 961 | - } | |
| 962 | - | |
| 963 | - inline | |
| 964 | - void | |
| 965 | - parse_value(const std::string& text, int32_t& value) | |
| 928 | + template <typename T, | |
| 929 | + typename std::enable_if<std::is_integral<T>::value>::type* = nullptr | |
| 930 | + > | |
| 931 | + void parse_value(const std::string& text, T& value) | |
| 966 | 932 | { |
| 967 | - integer_parser(text, value); | |
| 968 | - } | |
| 969 | - | |
| 970 | - inline | |
| 971 | - void | |
| 972 | - parse_value(const std::string& text, uint64_t& value) | |
| 973 | - { | |
| 974 | - integer_parser(text, value); | |
| 975 | - } | |
| 976 | - | |
| 977 | - inline | |
| 978 | - void | |
| 979 | - parse_value(const std::string& text, int64_t& value) | |
| 980 | - { | |
| 981 | - integer_parser(text, value); | |
| 933 | + integer_parser(text, value); | |
| 982 | 934 | } |
| 983 | 935 | |
| 984 | 936 | inline |
| ... | ... | @@ -1010,7 +962,9 @@ namespace cxxopts |
| 1010 | 962 | // The fallback parser. It uses the stringstream parser to parse all types |
| 1011 | 963 | // that have not been overloaded explicitly. It has to be placed in the |
| 1012 | 964 | // source code before all other more specialized templates. |
| 1013 | - template <typename T> | |
| 965 | + template <typename T, | |
| 966 | + typename std::enable_if<!std::is_integral<T>::value>::type* = nullptr | |
| 967 | + > | |
| 1014 | 968 | void |
| 1015 | 969 | parse_value(const std::string& text, T& value) { |
| 1016 | 970 | stringstream_parser(text, value); | ... | ... |