On Wed, 25 Jan 2012 23:08:01 -0500, bearophile <[email protected]>
wrote:
In this bug report I've seen an inout struct constructor:
http://d.puremagic.com/issues/show_bug.cgi?id=7369
struct TestStruct {
this(int data) inout {}
}
Do you know what's the usage of this?
I would say possibly something like this:
struct TestStruct {
int *data;
this(inout(int)* d) inout { this.data = d; } // allowed just like a
const ctor can set its members once.
}
int xm;
const(int) xc;
immutable(int) xi;
auto tsm = TestStruct(&xm);
auto tsc = TestStruct(&xc);
auto tsi = TestStruct(&xi);
writeln(typeof(tsm).stringof); // TestStruct
writeln(typeof(tsc).stringof); // const(TestStruct)
writeln(typeof(tsi).stringof); // immutable(TestStruct)
I'll note that I don't think this is currently supported, but I could see
how it would be useful.
However, in that bug report, there are no inout parameters besides the
'this' pointer, so I'm not sure what the purpose would be there.
-Steve