#include <iostream>
#include <regex>
static const std::regex INT_TYPE("[+-]?[0-9]+");
static const std::regex UNSIGNED_INT_TYPE("[+]?[0-9]+");
static const std::regex DOUBLE_TYPE("[+-]?[0-9]+[.]?[0-9]+");
static const std::regex UNSIGNED_DOUBLE_TYPE("[+]?[0-9]+[.]?[0-9]+");
bool isIntegerType(const std::string& str_)
{
return std::regex_match(str_, INT_TYPE);
}
bool isUnsignedIntegerType(const std::string& str_)
{
return std::regex_match(str_, UNSIGNED_INT_TYPE);
}
bool isDoubleType(const std::string& str_)
{
return std::regex_match(str_, DOUBLE_TYPE);
}
bool isUnsignedDoubleType(const std::string& str_)
{
return std::regex_match(str_, UNSIGNED_DOUBLE_TYPE);
}
int main()
{
std::string unsignedInteger("026564");
std::string integer("-2656");
std::string unsignedDouble("+0.2426564");
std::string Double("-0.24265640");
std::cout << std::boolalpha;
std::cout << unsignedInteger << ": is Unsigned Integer? " << isUnsignedIntegerType(unsignedInteger) << std::endl;
std::cout << integer << ": is Unsigned Integer? " << isUnsignedIntegerType(integer) << std::endl;
std::cout << unsignedDouble << ": is Unsigned Integer? " << isUnsignedIntegerType(unsignedDouble) << std::endl;
std::cout << Double << ": is Unsigned Integer? " << isUnsignedIntegerType(Double) << std::endl;
std::cout << std::endl;
std::cout << unsignedInteger << ": is Integer? " << isIntegerType(unsignedInteger) << std::endl;
std::cout << integer << ": is Integer? " << isIntegerType(integer) << std::endl;
std::cout << unsignedDouble << ": is Integer? " << isIntegerType(unsignedDouble) << std::endl;
std::cout << Double << ": is Integer? " << isIntegerType(Double) << std::endl;
std::cout << std::endl;
std::cout << unsignedInteger << ": is Unsigned Double? " << isUnsignedDoubleType(unsignedInteger) << std::endl;
std::cout << integer << ": is Unsigned Double? " << isUnsignedDoubleType(integer) << std::endl;
std::cout << unsignedDouble << ": is Unsigned Double? " << isUnsignedDoubleType(unsignedDouble) << std::endl;
std::cout << Double << ": is Unsigned Double? " << isUnsignedDoubleType(Double) << std::endl;
std::cout << std::endl;
std::cout << unsignedInteger << ": is Double? " << isDoubleType(unsignedInteger) << std::endl;
std::cout << integer << ": is Double? " << isDoubleType(integer) << std::endl;
std::cout << unsignedDouble << ": is Double? " << isDoubleType(unsignedDouble) << std::endl;
std::cout << Double << ": is Double? " << isDoubleType(Double) << std::endl;
std::cout << std::endl;
}