[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))
;
}
};
- [lmi-commits] [lmi] master updated (29808d8 -> 2f1cecc), Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 27584b1 1/8: Use is_signed to differentiate between signed and unsigned,
Greg Chicares <=
- [lmi-commits] [lmi] master 895c823 3/8: Do not make variable initialized with ldexp() constexpr, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master b5fe551 4/8: Write 'const' after the type it modifies, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master a9c5ed5 7/8: Resolve a marked defect [389], Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 6327528 6/8: Use C++11 overloads for C99 <math.h> functions, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 461c143 2/8: Replace boost::numeric_cast with bourn_cast, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master dea45f1 5/8: Avoid 'static constexpr' locals, Greg Chicares, 2017/04/24
- [lmi-commits] [lmi] master 2f1cecc 8/8: Explicitly qualify std::fabs(), Greg Chicares, 2017/04/24