[Issue 13685] std.numeric.arrayShape

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Nov 5 01:53:56 PST 2014


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

--- Comment #1 from bearophile_hugs at eml.cc ---
If arrayShape returns a specialized struct instead of a generic tuple, then
it's possible to add a method to the struct (otherwise a free function that
takes a tuple is acceptable using UFCS), like "allocate", that allows to create
an array of given shape:

auto a1 = new int[][](10, 5);
auto s1 = a1.arrayShape;
auto a2 = s1.allocate!double; // 2D matrix of NaNs doubles.
assert(a1.arrayShape == a2.arrayShape);
auto a3 = s1.allocate!double(5.0); // Initialized to 5.0.
assert(a1.arrayShape == a3.arrayShape);
auto a4 = s1.allocate!double((r, c) => r * c); // Initialized to r*c.
assert(a1.arrayShape == a4.arrayShape);

--


More information about the Digitalmars-d-bugs mailing list