xxxxxxxxxx
import std.stdio;
import std.traits;
struct S
{
int[] arr;
}
interface I
{
inout(I) opIndex(size_t idx) inout;
}
class Test(T) : I
{
// Error: variable `onlineapp.Test!(inout(int)[]).Test.member` only parameters or stack based variables can be inout
T member;
this(inout T mem) inout
{
this.member = mem;
}
inout(Test) get() inout
{
return new inout Test(member);
}
inout(I) opIndex(size_t idx) inout
{
static if(is(T == struct))
{
switch (idx)
static foreach (index, t; T.tupleof)
{
case index:
// Error: template instance `onlineapp.Test!(inout(int)[])` error instantiating
return new inout
Test!(typeof(T.tupleof[index]))
(this.member.tupleof[index]);
default:
return null;
}
}
else
// FIXME
return new inout Test!(int)(1);
}
}
unittest
{
auto s = S([1,2,3]);
auto t = new const Test!S(s);
}
void main() {}