[Issue 13685] New: std.numeric.arrayShape

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Nov 4 03:05:03 PST 2014


https://issues.dlang.org/show_bug.cgi?id=13685

          Issue ID: 13685
           Summary: std.numeric.arrayShape
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: bearophile_hugs at eml.cc

I suggest to add to Phobos a simple function "arrayShape", that given a nD
array performs:
1) calls isRectangular (Issue 13684 ) to verify the input array is complete.
2) Returns a n-tuple of the lengths of matrix sides.

Examples:

arrayShape([1, 2]) => tuple(2)
arrayShape([[1, 2], [3, 4], [5, 6]]) => tuple(3, 2)
arrayShape([[1, 2], [3], [5, 6]]) => exception

This is useful to quickly compare the shape of nD arrays, when you need them to
be of the same sizes:


void foo(int[][] a1, float[][] a2)
in {
    assert(a1.arrayShape == a2.arrayShape);
} body {}

--


More information about the Digitalmars-d-bugs mailing list