#ifndef __INT__
#define __INT__
#include "Comparison.hpp"
#include <string>
namespace Lib {
class Int
{
public:
static std::string toString(int i);
static std::string toString(unsigned i);
static std::string toString(unsigned long i);
static std::string toString(long l);
static std::string toString(float f) { return toString((double)f); }
static std::string toString(double d);
inline static Comparison compare (int i1, int i2)
{ return i1 < i2 ? LESS : i1 == i2 ? EQUAL : GREATER; }
inline static Comparison compare (unsigned i1, unsigned i2)
{ return i1 < i2 ? LESS : i1 == i2 ? EQUAL : GREATER; }
inline static Comparison compare (long i1, long i2)
{ return i1 < i2 ? LESS : i1 == i2 ? EQUAL : GREATER; }
inline static Comparison compare (unsigned long i1, unsigned long i2)
{ return i1 < i2 ? LESS : i1 == i2 ? EQUAL : GREATER; }
inline static Comparison compare (const void* p1, const void* p2)
{ return p1 < p2 ? LESS : p1 == p2 ? EQUAL : GREATER; }
inline static Comparison compare (float f1, float f2)
{ return f1 < f2 ? LESS : f1 == f2 ? EQUAL : GREATER; }
inline static Comparison compare (double f1, double f2)
{ return f1 < f2 ? LESS : f1 == f2 ? EQUAL : GREATER; }
static bool stringToLong(const char*,long& result);
static bool stringToUnsignedLong(const char*,unsigned long& result);
static bool stringToLong(const std::string& str,long& result) {
return stringToLong(str.c_str(),result);
}
static bool stringToInt(const std::string& str,int& result);
static bool stringToInt(const char* str,int& result);
static bool stringToUnsignedInt(const char* str,unsigned& result);
static bool stringToUnsignedInt(const std::string& str,unsigned& result);
static bool stringToDouble(const char*,double& result);
static bool stringToDouble(const std::string& str,double& result) { return stringToDouble(str.c_str(), result); }
static bool stringToFloat(const char*,float& result);
static bool stringToUnsigned64(const std::string& str,long long unsigned& result);
static bool stringToUnsigned64(const char* str,long long unsigned& result);
};
template <typename T>
using disable_deduction = typename std::enable_if_t<true, T>;
template <typename T>
inline bool isAdditionOverflow(disable_deduction<T> a, disable_deduction<T> b)
{
static_assert(std::is_unsigned<T>::value, "overflow check is only defined for unsigned types");
return static_cast<T>(a + b) < a;
}
}
#endif