www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13685] New: std.numeric.arrayShape

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 puremagic.com
          Reporter: bearophile_hugs 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 {}

--
Nov 04 2014