Conversion to numeric types

unsigned_int<> supprts conversion to any numeric type (say T), using a templated operator T ().

std::ostream cout( std::cout.rdbuf() );

unsigned_int< 128 > a( "0x110000" ), b(0);
CHECK( (bool)a );
CHECK( !(bool)b );
CHECK( b ? false : true );
CHECK( a ? true : false );
CHECK( (unsigned short)a == 0U );
CHECK( (unsigned)a == 0x110000U );
CHECK( (double)a == (double)0x110000U );

std::cout << "(unsigned short)a " << (unsigned short)a << "\n";
std::cout << "(short)a " << (short)a << "\n";

short i = a;

cout
  << "i (after short i = "<< std::hex << a << ") "
  << std::dec << i << "\n"
;

if ( a ) CHECK( !i );

double d = 0x110000U * 3.45e7;
a = d;
CHECK_PRINT( (double)a == d, a << " != " << d );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

(unsigned short)a 0
(short)a 0
i (after short i = 110000) 0
Ok