multidimArray

Convenience function that returns an MultidimArray!(T, n) object.

  1. auto multidimArray(size_t[n] lengths)
  2. auto multidimArray(T[] data, size_t[n] lengths)
  3. auto multidimArray(A array)
  4. auto multidimArray(A array)
  5. auto multidimArray(A array)
    @safe pure nothrow
    multidimArray
    (
    size_t n
    A
    )
    ()
    if (
    isDynamicArray!A &&
    n > 0
    &&
    n - 1 <= staticArrayDims!(ElementType!A)
    )
  6. auto multidimArray(A array)

Parameters

array A

An array to wrap. It can be a multidimensional static array or a slice of it (has a dynamic top dimension).

Return Value

Type: auto

The first overload returns a MultidimArray with a newly allocated data Others use an existing storage.

Throws

The first overload throws an RangeError in debug build if data length isn't equal to lengths prouct.

Examples

t
{
	// Let's create an GC allocated three-dimensional rectangular array from 2 matrices 3x4
	auto matrix1 = multidimArray!int(2, 3, 4);

	// Let's create the same array using an existing storage
	auto darr2 = new int[24]; // At least 24 elements are needed
	auto matrix2 = multidimArray(darr2, 2, 3, 4); // No need for explicit element type declaration

	// Let's create the same array using an existing static array as data storage
	int[4][3][2] sarr3; // or in a postfix form: int sarr[2][3][4];
	auto matrix3 = multidimArray(sarr3); // No need for any explicit template declarations

	// The head array can be dynamic
	int[4][3][] darr3 = sarr3[];
	auto matrix31 = multidimArray(darr3); // Works like previous one

	// Let's create an array of static arrays
	ubyte[4][4][3][2] sarr4; // a postfix form: ubyte[4] sarr[2][3][4];
	auto matrix4 = multidimArray!3(sarr4); // Only 3 major of 4 dimensions are indeces

	// The head array can also be dynamic
	auto matrix41 = multidimArray!3(sarr4[]); // Works like previous o

See Also

MultidimArray

Meta