<div class="gmail_quote">On 14 March 2012 22:10, Ary Manzana <span dir="ltr"><<a href="mailto:ary@esperanto.org.ar">ary@esperanto.org.ar</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On 3/14/12 5:00 PM, Simen Kjærås wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana <<a href="mailto:ary@esperanto.org.ar" target="_blank">ary@esperanto.org.ar</a>><br>
wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Here's what you can do in Ruby:<br>
<br>
a = 1<br>
b = 2<br>
<br>
# Swap the contents<br>
a, b = b, a<br>
<br>
Can you do something like that with templates in D, with a nice syntax?<br>
</blockquote>
<br>
template to(T...) {<br>
alias T to;<br>
}<br>
<br>
auto from(T...)(T t) {<br>
struct Result { T t; alias t this; }<br>
return Result( t );<br>
}<br>
<br>
void main( ) {<br>
int a = 3;<br>
int b = 4;<br>
<br>
to!(a, b) = from(b, a);<br>
<br>
assert( a == 4 );<br>
assert( b == 3 );<br>
}<br>
</blockquote>
<br></div></div>
Awesome! :-)</blockquote><div><br></div><div>Mmmm, I still kinda like the ruby way.</div><div>I agree, the coma operator is a serious liability in D. Multi assignments without any other rubbish around it are useful in a whole bunch of of contexts.</div>
<div>How much would really break if coma was deprecated? Is it used any more than C++ coma? (Most C++ programs wouldn't even know if the coma operator were removed)</div></div>