diff options
Diffstat (limited to 'src/base/str.hh')
-rw-r--r-- | src/base/str.hh | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/base/str.hh b/src/base/str.hh index 61022bd26..1ea18b70d 100644 --- a/src/base/str.hh +++ b/src/base/str.hh @@ -40,6 +40,7 @@ #include <locale> #include <stdexcept> #include <string> +#include <type_traits> #include <vector> #include "base/logging.hh" @@ -108,8 +109,7 @@ tokenize(std::vector<std::string> &vector, const std::string &s, * integeral type, as well as enums and floating-point types. */ template <class T> -typename std::enable_if<(std::is_integral<T>::value || - std::is_enum<T>::value) && +typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value, T>::type __to_number(const std::string &value) { @@ -121,8 +121,7 @@ __to_number(const std::string &value) } template <class T> -typename std::enable_if<(std::is_integral<T>::value || - std::is_enum<T>::value) && +typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value, T>::type __to_number(const std::string &value) { @@ -134,6 +133,14 @@ __to_number(const std::string &value) } template <class T> +typename std::enable_if<std::is_enum<T>::value, T>::type +__to_number(const std::string &value) +{ + auto r = __to_number<typename std::underlying_type<T>::type>(value); + return static_cast<T>(r); +} + +template <class T> typename std::enable_if<std::is_floating_point<T>::value, T>::type __to_number(const std::string &value) { |