From f9bd874b7f892f6755e9744822e7a7a8e979cf09 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 20 Oct 2020 19:11:07 -0700 Subject: [PATCH] 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 --- src/base/str.hh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 { -- 2.30.2