[code] Unsigned!T encodeZigZag( T )( inout T v ) pure if( isSigned!( T ) ) { return v > 0 ? v * 2 : -v * 2 - 1; } unittest { assert( encodeZigZag!long( 2147483647 ) == 4294967294 ); assert( encodeZigZag!long( -2147483648 ) == 4294967295 );
assert( encodeZigZag!short( 20 ) == 40 ); assert( encodeZigZag!short( -20 ) == 39 ); } [/code] Error: cannot implicitly convert expression (cast(int)v > 0 ? cast(int)v * 2 : cast(int)-v * 2 - 1) of type int to ushort int?!