How to compile this template with short type?

mrd denis.feklushkin at gmail.com
Tue Sep 17 00:58:38 PDT 2013


[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?!


More information about the Digitalmars-d-learn mailing list