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