]> git.tdb.fi Git - libs/core.git/blobdiff - source/strings/lexicalcast.cpp
Fix signedness errors from MSVC
[libs/core.git] / source / strings / lexicalcast.cpp
index 1c1f72010cc49c6b55c9013b4fc5bd4fbd662d75..2c867b2ce0572b7489a7fb6c9e74013efb6b7804 100644 (file)
@@ -19,6 +19,14 @@ template<typename T>
 struct IsNegative<T, false>
 { static bool eval(T) { return false; } };
 
+template<typename T, bool f = is_signed<T>::value>
+struct Negate
+{ static T eval(T v) { return -v; } };
+
+template<typename T>
+struct Negate<T, false>
+{ static T eval(T v) { return (~v)+1; } };
+
 /* Helper to avoid errors about ambiguous function calls since there are no
 overloads of abs for unsigned types */
 template<typename T, bool f = is_signed<T>::value>
@@ -170,7 +178,7 @@ T str_to_int(const string &s, const Fmt &f)
        }
 
        if(neg)
-               result = -result;
+               result = Negate<T>::eval(result);
 
        return result;
 }