array help.

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 8 11:40:34 PDT 2014


NA:

> will not work and no I can't sort it.

Why no sort?


void main() {
     import std.algorithm: sort, SwapStrategy;
     import std.array: empty;

     int[][][][] a =
         [[[],
           [],
           [],
           [],
           [[0, 1], [0, 2]],
           [[0, 0], [0, 3]]
          ],
          [[],
           [],
           [],
           [],
           [[1, 1], [1, 2]],
           [[1, 0], [1, 3]]
          ]
         ];

     int[][][][] b =
         [[[[0, 1], [0, 2]],
           [[0, 0], [0, 3]],
           [],
           [],
           [],
           []
          ],
          [[[1, 1], [1, 2]],
           [[1, 0], [1, 3]],
           [],
           [],
           [],
           []
          ]
         ];

     foreach (s1; a)
         s1.sort!(q{ a.empty < b.empty }, SwapStrategy.stable);
     assert(a == b);
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list