On 14 March 2012 22:10, Ary Manzana <a...@esperanto.org.ar> wrote: > On 3/14/12 5:00 PM, Simen Kjærås wrote: > >> On Wed, 14 Mar 2012 20:02:50 +0100, Ary Manzana <a...@esperanto.org.ar> >> wrote: >> >> Here's what you can do in Ruby: >>> >>> a = 1 >>> b = 2 >>> >>> # Swap the contents >>> a, b = b, a >>> >>> Can you do something like that with templates in D, with a nice syntax? >>> >> >> template to(T...) { >> alias T to; >> } >> >> auto from(T...)(T t) { >> struct Result { T t; alias t this; } >> return Result( t ); >> } >> >> void main( ) { >> int a = 3; >> int b = 4; >> >> to!(a, b) = from(b, a); >> >> assert( a == 4 ); >> assert( b == 3 ); >> } >> > > Awesome! :-)
Mmmm, I still kinda like the ruby way. 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. 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)