Re: sort struct of arrays

2014-05-09 Thread anonymous via Digitalmars-d-learn
On Friday, 9 May 2014 at 14:23:41 UTC, Luís Marques wrote: If you have an array of structs, such as... struct Foo { int x; int y; } Foo[] foos; ...and you wanted to sort the foos then you'd do something like... foos.sort!(a.x b.x), ..and, of

Re: sort struct of arrays

2014-05-09 Thread via Digitalmars-d-learn
On Friday, 9 May 2014 at 14:48:50 UTC, anonymous wrote: std.range.zip(fooX, fooY).sort!((a, b) = a[0] b[0]); I wasn't sure if that's supposed to work. Turns out the documentation on zip [1] has this exact use case as an example. [1] http://dlang.org/phobos/std_range.html#zip Ha! Awesome!

Re: sort struct of arrays

2014-05-09 Thread John Colvin via Digitalmars-d-learn
On Friday, 9 May 2014 at 14:23:41 UTC, Luís Marques wrote: If you have an array of structs, such as... struct Foo { int x; int y; } Foo[] foos; ...and you wanted to sort the foos then you'd do something like... foos.sort!(a.x b.x), ..and, of

Re: sort struct of arrays

2014-05-09 Thread Rene Zwanenburg via Digitalmars-d-learn
On Friday, 9 May 2014 at 15:52:51 UTC, John Colvin wrote: On Friday, 9 May 2014 at 14:23:41 UTC, Luís Marques wrote: If you have an array of structs, such as... struct Foo { int x; int y; } Foo[] foos; ...and you wanted to sort the foos then you'd do something

Re: sort struct of arrays

2014-05-09 Thread John Colvin via Digitalmars-d-learn
On Friday, 9 May 2014 at 16:26:22 UTC, Rene Zwanenburg wrote: On Friday, 9 May 2014 at 15:52:51 UTC, John Colvin wrote: On Friday, 9 May 2014 at 14:23:41 UTC, Luís Marques wrote: If you have an array of structs, such as... struct Foo { int x; int y; } Foo[] foos;