You can avoid cast:

void foo(T)(T bar){...}

byte bar = 9;

foo!byte(bar + byte(1));

or

byte bar = 9;
byte num = 1;
foo!byte(bar + num);



On Tue, Oct 10, 2017 at 9:55 PM, Chirs Forest via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com> wrote:
I keep having to make casts like the following and it's really rubbing me the wrong way:

void foo(T)(T bar){...}

byte bar = 9;

foo!byte(bar + 1); //Error: function foo!byte.foo (byte bar) is not callable using argument types (int)
foo!byte(cast(byte)(bar + 1));

It wouldn't be so bad if I didn't have to use the word cast before each cast, bust since I have to specify both the word cast and the cast type and then wrap both the cast type and the value in brackets... it just explodes my code into multiple lines of unreadable mess.


void foo(T)(T bar, T bar2, T bar3){...}

byte foobar = 12;

foo!byte(foobar + 1, foobar + 22, foobar + 333);
vs.
foo!byte(cast(byte)(foobar + 1), cast(byte)(foobar + 22), cast(byte)(foobar + 333));

Why?