Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/36279 )

Change subject: base: Narrow the applicability of the default to_number.
......................................................................

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 <gabe.bl...@gmail.com>
Reviewed-by: Andreas Sandberg <andreas.sandb...@arm.com>
Maintainer: Gabe Black <gabe.bl...@gmail.com>
Maintainer: Andreas Sandberg <andreas.sandb...@arm.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/str.hh
1 file changed, 6 insertions(+), 3 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/str.hh b/src/base/str.hh
index 5e56e62..8c05a8d 100644
--- a/src/base/str.hh
+++ b/src/base/str.hh
@@ -156,15 +156,18 @@
 /** @} */

 /**
- * 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 <class T>
-inline bool
+inline std::enable_if_t<(std::is_integral<T>::value ||
+                         std::is_floating_point<T>::value ||
+                         std::is_enum<T>::value) &&
+                        !std::is_same<bool, T>::value, bool>
 to_number(const std::string &value, T &retval)
 {
     try {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/36279
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib29a9a0ea75dd617e28bb6850d60be905f93182f
Gerrit-Change-Number: 36279
Gerrit-PatchSet: 4
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to