Constrction and Assignment

Construction

unsigned_int<> has a templated constuctor that can construct an unsigned_int<> from any inbuilt numeric type (int, double etc).

The templated constructor is excluded (by SFINAE) from taking an argument that is another User Defined Type or isn't a numeric type, this prevents there from being two equal convertions from a different unsigned_int<>.

Additionally unsigned_int<> has an explicit constructor from char const (&)[ N ] as a substitute for the lack of any literal's, the format is ([0-9][xX])?[0-9a-zA-Z]. A leading nX sequence determins the base of the following digits (n = 0 -> hexadecimal, n = 1 through 9 -> base (n + 1)). See operator << for examples.

unsigned_int< 128 > a( 10 ), b = -1, c( 2.4e7 ), d("9"), e( a );

std::cout << "unsigned_int< 128 > a( 10 ): " << a << '\n';
CHECK( a == 10 );
std::cout << "unsigned_int< 128 > b = -1: " << b << '\n';
CHECK( b == -1 );
std::cout << "unsigned_int< 128 > c( 2.4e7 ): " << c << '\n';
CHECK( c == 2.4e7 );
std::cout << "unsigned_int< 128 > d(\"9\"): " << d << '\n';
CHECK( d == 9 );
std::cout << "unsigned_int< 128 > e( a ): " << e << '\n';
CHECK( e == a );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

unsigned_int< 128 > a( 10 ): 10
unsigned_int< 128 > b = -1: 340282366920938463463374607431768211455
unsigned_int< 128 > c( 2.4e7 ): 24000000
unsigned_int< 128 > d("9"): 9
unsigned_int< 128 > e( a ): 10
Ok

Assignment

unsigned_int< 128 > c, d;
unsigned_int< 128 > const cc( "0x1234567890123456789" );

c = 20;
std::cout << "c = 20: " << c << '\n';
CHECK( c == 20 );

d = c;
CHECK( d == 20 && d == c && c == d );
d = char( 9 );
std::cout << "d = char( 9 ): " << d << '\n';
CHECK( d == 9 );

d = cc;
CHECK( d == cc );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

c = 20: 20
d = char( 9 ): 9
Ok

SFINAE:Substitution Failure Is Not An Error.