www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Swap operator ?

reply BLS <nanali nospam-wanadoo.fr> writes:
Not really nessesary, but nice to have...
int a = 1;
int b = 2;
a <=> b // a == 2, b == 1
Oct 10 2007
next sibling parent Jascha Wetzel <firstname mainia.de> writes:
BLS wrote:
 Not really nessesary, but nice to have...
 int a = 1;
 int b = 2;
 a <=> b // a == 2, b == 1
i use: void swap(T)(ref T a, ref T b) { T t = a; a = b; b = t; } int a = 1; int b = 2; swap(a,b);
Oct 10 2007
prev sibling next sibling parent reply Matti Niemenmaa <see_signature for.real.address> writes:
BLS wrote:
 Not really nessesary, but nice to have...
 int a = 1;
 int b = 2;
 a <=> b // a == 2, b == 1
Or multiple return values, and then: a, b = b, a; -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Oct 10 2007
parent reply Michael Gnail <gnail.f gmail.com> writes:
Matti Niemenmaa wrote:
 BLS wrote:
 Not really nessesary, but nice to have...
 int a = 1;
 int b = 2;
 a <=> b // a == 2, b == 1
Or multiple return values, and then: a, b = b, a;
This is the *python* way, and I love that too.
Oct 11 2007
parent reply Bill Baxter <dnewsgroup billbaxter.com> writes:
Michael Gnail wrote:
 Matti Niemenmaa wrote:
 BLS wrote:
 Not really nessesary, but nice to have...
 int a = 1;
 int b = 2;
 a <=> b // a == 2, b == 1
Or multiple return values, and then: a, b = b, a;
This is the *python* way, and I love that too.
I don't know where that syntax came from, but but I'm pretty sure it predates python by a good bit. Probably Ada or something. --bb
Oct 11 2007
parent David Brown <dlang davidb.org> writes:
On Fri, Oct 12, 2007 at 08:15:30AM +0900, Bill Baxter wrote:

 a, b = b, a;
This is the *python* way, and I love that too.
I don't know where that syntax came from, but but I'm pretty sure it predates python by a good bit. Probably Ada or something.
Ada doesn't have multiple assignment. CLU had it in 1974, though. David
Oct 11 2007
prev sibling parent BLS <nanali nospam-wanadoo.fr> writes:
BLS schrieb:
 Not really nessesary, but nice to have...
 int a = 1;
 int b = 2;
 a <=> b // a == 2, b == 1
Sorry folks, just have recognized that this stuff is allready part of the chapel thread; B
Oct 11 2007