xxxxxxxxxx
import std.traits;
struct S
{
int[3] arr;
}
struct SS
{
S s;
}
interface I
{
inout(I) opIndex(size_t idx) inout;
}
class Test(T) : I
{
T member;
this(inout T mem) inout
{
this.member = mem;
}
inout(Test!T) get() inout
{
return new inout Test!(Unqual!(typeof(member)))(member);
}
inout(I) opIndex(size_t idx) inout
{
static if (is(T == struct))
{
switch (idx)
static foreach (index, t; T.tupleof)
{
case index:
return new inout
Test!(Unqual!(typeof(this.member.tupleof[index])))
(this.member.tupleof[index]);
default:
return null;
}
}
else
return null;
}
}
auto test(T)(inout T t)
{
return new inout Test!(Unqual!T)(t);
}
class TestA(T : T[])
{
Test!T[] arr;
this(inout(T[]) arr) inout
{
// 1: Nope
foreach (mem; arr)
this.arr ~= test(mem);
// 2: Nope
//Test!T[] a;
//foreach (mem; arr)
// a ~= test(mem);
import std.algorithm : map;
// 3: Nope
// this.arr = arr.map!((e) => test(e)).array;
}
}
void main()
{
auto ss = SS(S([1,2,3]));
auto t = new const Test!SS(ss);
auto ta = new const TestA!(Test!SS[])([t]);
}