operator ++ () and operator -- ()

unsigned_int<> supports prefix and postfix ++ and -- with the usual symantics.

typedef unsigned_int< (2 * UINT_BITS) > uint2t;

uint2t d = 9;

CHECK( d++ == 9 );
CHECK( d == 10 );
CHECK( d-- == 10 );
CHECK( d == 9 );

CHECK( ++d == 10 );
CHECK( d == 10 );
CHECK( --d == 9 );
CHECK( d == 9 );

uint2t mul =  uint2t( 1 ) << (UINT_BITS - 1);

d *= mul;
uint2t save = d;

CHECK( (--d) == ( save - 1 ) );
CHECK( d == ( save - 1 ) );
CHECK( (++d) == save );
CHECK( d == save );

CHECK( (d--) == save );
CHECK( d == ( save - 1 ) );
CHECK( (d++) == ( save - 1 ) );
CHECK( d == save );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Output

Ok

const

Operators ++ and -- only apply to non-const values.

unsigned_int< 128 > const d( 9 );

++d;

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Warning

./gensrc/incdec-unsigned-id-ref-fail.cpp:38:
: binary '++' : no operator found which takes a left-hand operand of type 'const imp::unsigned_int_s::unsigned_int<N>' (or there is no acceptable conversion)
        with
        [
            N=128
        ]
++( unsigned_int< 128 >( 99 ) );

Test Result: gcc34 Passed, msvc80 Passed, msvc71 Passed

Warning

./gensrc/incdec-unsigned-id-temp-fail.cpp:36:
: binary '++' : no operator found which takes a left-hand operand of type 'imp::unsigned_int_s::unsigned_int<N>' (or there is no acceptable conversion)
        with
        [
            N=128
        ]