base: Prevent undefined behavior in not interleaved `AddrRange`s.
[gem5.git] / src / base / str.hh
index 5e56e622d87f42b461a6db26595ef65430cde1c8..40fd780fdd7cddcfc0af6dc24ec12193dc98db8d 100644 (file)
@@ -108,8 +108,8 @@ 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_signed<T>::value, T>::type
+typename std::enable_if_t<std::is_integral<T>::value &&
+                          std::is_signed<T>::value, T>
 __to_number(const std::string &value)
 {
     // start big and narrow it down if needed, determine the base dynamically
@@ -122,8 +122,8 @@ __to_number(const std::string &value)
 }
 
 template <class T>
-typename std::enable_if<std::is_integral<T>::value &&
-                        !std::is_signed<T>::value, T>::type
+typename std::enable_if_t<std::is_integral<T>::value &&
+                          !std::is_signed<T>::value, T>
 __to_number(const std::string &value)
 {
     // start big and narrow it down if needed, determine the base dynamically
@@ -134,7 +134,7 @@ __to_number(const std::string &value)
 }
 
 template <class T>
-typename std::enable_if<std::is_enum<T>::value, T>::type
+typename std::enable_if_t<std::is_enum<T>::value, T>
 __to_number(const std::string &value)
 {
     auto r = __to_number<typename std::underlying_type<T>::type>(value);
@@ -142,7 +142,7 @@ __to_number(const std::string &value)
 }
 
 template <class T>
-typename std::enable_if<std::is_floating_point<T>::value, T>::type
+typename std::enable_if_t<std::is_floating_point<T>::value, T>
 __to_number(const std::string &value)
 {
     // start big and narrow it down if needed
@@ -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 <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 {