<div dir="ltr">You can avoid cast:<div><br></div><div><span style="font-size:12.8px">void foo(T)(T bar){...}</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">byte bar = 9;</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">foo!byte(bar + byte(1));</span><br></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">or</span></div><div><span style="font-size:12.8px"><br></span></div><div><div><span style="font-size:12.8px">byte bar = 9;</span><br style="font-size:12.8px">byte num = 1;<br style="font-size:12.8px"><span style="font-size:12.8px">foo!byte(bar + num);</span><br></div></div><div><span style="font-size:12.8px"><br></span></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 10, 2017 at 9:55 PM, Chirs Forest via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I keep having to make casts like the following and it's really rubbing me the wrong way:<br>
<br>
void foo(T)(T bar){...}<br>
<br>
byte bar = 9;<br>
<br>
foo!byte(bar + 1); //Error: function foo!byte.foo (byte bar) is not callable using argument types (int) <br>
foo!byte(cast(byte)(bar + 1));<br>
<br>
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.<br>
<br>
<br>
void foo(T)(T bar, T bar2, T bar3){...}<br>
<br>
byte foobar = 12;<br>
<br>
foo!byte(foobar + 1, foobar + 22, foobar + 333);<br>
vs.<br>
foo!byte(cast(byte)(foobar + 1), cast(byte)(foobar + 22), cast(byte)(foobar + 333));<br>
<br>
Why?<br>
</blockquote></div><br></div>