#include < sstream>
#include < string>
#include < iostream>
#include < typeinfo>
#include < stdlib.h>

template < typename T>
static T convert(std::string const &v) {
std::istringstream ss(v);
std::cout << "General Conversion of " << v << std::endl;
T rv;
ss >> rv;

if (!rv && (0 == v.compare(0, 2, "0x") || 0 == v.compare(0, 2, "0X"))) {
std::istringstream ss(v);
std::cout << "This appears to be returning a number and the input appears to be HEX." << std::endl;
ss >> std::hex >> rv;
} else if (!rv && (0 == v.compare(0, 3, "-0x") || 0 == v.compare(0, 3, "-0X"))) {
std::istringstream ss(v);
std::cout << "This appears to be returning a number and the input appears to be -HEX." << std::endl;
ss >> std::hex >> rv;
}

return rv;
}
template<>
bool convert< bool>(std::string const &v) {
std::istringstream ss(v);
bool rv;
bool result = (ss >> std::boolalpha >> rv);
std::cout << "Bool Conversion of " << v << std::endl;
if (!result) {
std::cout << "Failed.. Fallback Mechanism Inistiating..." << std::endl;
if (v[0] == `t` || v[0] == `T` || v[0] == `y` || v[0] == `Y` || v[0] == `1`)
return true;
if ((v[0] == `O` || v[0] == `o`) && (v[1] == `n` || v[1] == `N`))
return true;
return false;
}
return rv;
}

class C {
public:
template
static T conv(std::string const &v) {
return convert< T>(v);
};
};


int main() {
int i, h, h2;
bool b;
double d;

i = C::conv("100");
h = C::conv("0xff");
h2 = C::conv("-0Xff");
b = C::conv("True");
d = C::conv("2.3");

std::cout << i << " " << h << " " << h2 << " " << b << " " << d << std::endl;
}