On Thursday, 2 February 2023 at 05:47:34 UTC, Paul Backus wrote:
Here's a solution using standard-library functions:
```d
import std.range: transversal;
import std.algorithm: map, fill;
import std.stdio: writefln;
void main()
{
byte[3][3] myArr;
myArr[]
.map!((ref row) => row[])
.transversal(0)
.fill(byte(5));
writefln("%(%s\n%)", myArr[]);
}
```
https://d.godbolt.org/z/orernGc9b
Thank you for your contribution. In this way, we can find the
opportunity to compare. It can be seen below that the structure
(LimitedArray) implemented with union is at least 15 times and at
most 20 times faster.
```d
import std.stdio, std.algorithm, std.range;
import std.datetime.stopwatch;
enum set {
COL = 8, ROW = 65535
}
void main()
{
ubyte[set.COL][set.ROW] sArray;
auto lArray = LimitedArray!(set.COL)(set.ROW);
auto ds = [ Duration.zero, Duration.zero ];
auto sw = StopWatch(AutoStart.yes);
#line 1
sArray[].map!((ref row) =>
row[]).transversal(0).fill(byte.max);
ds[0] = sw.peek();
#line 2
lArray.cell.each!((ref c) =>
c.elements[0] = byte.max);
sw.stop();
/*
sArray.writefln!"%(%s\n%)";
lArray.print();//*/
writefln!"#line1 %s µs"(ds[0].total!"usecs");
ds[1] = sw.peek - ds[0];
writefln!"#line2 %s µs"(ds[1].total!"usecs");
"Percent %".writeln(ds[0]/ds[1]);
} /*
#line1 3362 µs
#line2 233 µs
Percent %14
*/
```
SDB@79