On Friday, 28 February 2020 at 16:51:10 UTC, AB wrote:
On Thursday, 27 February 2020 at 14:15:26 UTC, p.shkadzko wrote:
[...]

Your Example with a minimal 2D array.

------------
module test2;

import std.random : Xorshift, unpredictableSeed, uniform;
import std.range : generate, take, chunks;
import std.array : array;
import std.stdio : writeln;

struct Matrix(T)
{
 int rows;
 T[] data;
 alias data this;
 int cols() {return cast(int) data.length/rows;}
 this(int r, int c) { data=new int[r*c]; rows=r;}
this(int r, int c, T[] d) {assert(r*c==data.length); data=d; rows=r; }

 auto opIndex(int r, int c) {return data[rows*c+r];}

}

Can you please explain what is the purpose of "alias data this" in your Matrix struct? As I remember "alias <member> this" is used for implicit type conversions but I don't see where "data" is converted.

Reply via email to