From: Gabe Black Date: Wed, 21 Oct 2020 02:11:07 +0000 (-0700) Subject: base: Narrow the applicability of the default to_number. X-Git-Tag: develop-gem5-snapshot~583 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f9bd874b7f892f6755e9744822e7a7a8e979cf09;p=gem5.git base: Narrow the applicability of the default to_number. That template only works for integral (except bool), floating point, or enum types, so restrict it to those types. That makes it easier to detect what types will work with that function. Change-Id: Ib29a9a0ea75dd617e28bb6850d60be905f93182f Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/36279 Reviewed-by: Gabe Black Reviewed-by: Andreas Sandberg Maintainer: Gabe Black Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/base/str.hh b/src/base/str.hh index 5e56e622d..8c05a8d13 100644 --- a/src/base/str.hh +++ b/src/base/str.hh @@ -156,15 +156,18 @@ __to_number(const std::string &value) /** @} */ /** - * Turn a string representation of a number, either integral or - * floating point, into an actual number. + * Turn a string representation of a number, either integral, floating point, + * or enum into an actual number. Use to_bool for booleans. * * @param value The string representing the number * @param retval The resulting value * @return True if the parsing was successful */ template -inline bool +inline std::enable_if_t<(std::is_integral::value || + std::is_floating_point::value || + std::is_enum::value) && + !std::is_same::value, bool> to_number(const std::string &value, T &retval) { try {