lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 27584b1 1/8: Use is_signed to differentiate b


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 27584b1 1/8: Use is_signed to differentiate between signed and unsigned
Date: Mon, 24 Apr 2017 16:43:50 -0400 (EDT)

branch: master
commit 27584b16697a9dd8ade1f16cd0aebdcd9bc7586f
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Use is_signed to differentiate between signed and unsigned
    
    std::numeric_limits has two members that might be used to distinguish
    between signed and unsigned, more or less. Formerly, 0==min() was used;
    this has been replaced by is_signed, which is more natural, and has the
    further virtue of not being incorrect for bool.
---
 numeric_io_traits.hpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/numeric_io_traits.hpp b/numeric_io_traits.hpp
index c47d2ae..7f69eb6 100644
--- a/numeric_io_traits.hpp
+++ b/numeric_io_traits.hpp
@@ -157,16 +157,16 @@ template<> struct numeric_conversion_traits<char>
     typedef char T;
     static char const* fmt()
         {
-        return (0 == std::numeric_limits<T>::min())
-            ? "%.*u"
-            : "%.*i"
+        return std::numeric_limits<T>::is_signed
+            ? "%.*i"
+            : "%.*u"
             ;
         }
     static T strtoT(char const* nptr, char** endptr)
         {
-        return (0 == std::numeric_limits<T>::min())
-            ? boost::numeric_cast<T>(std::strtoul(nptr, endptr, 10))
-            : boost::numeric_cast<T>(std::strtol (nptr, endptr, 10))
+        return std::numeric_limits<T>::is_signed
+            ? boost::numeric_cast<T>(std::strtol (nptr, endptr, 10))
+            : boost::numeric_cast<T>(std::strtoul(nptr, endptr, 10))
             ;
         }
 };



reply via email to

[Prev in Thread] Current Thread [Next in Thread]