inout constructor?
    Steven Schveighoffer 
    schveiguy at yahoo.com
       
    Thu Jan 26 07:27:50 PST 2012
    
    
  
On Wed, 25 Jan 2012 23:08:01 -0500, bearophile <bearophileHUGS at lycos.com>  
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
    
    
More information about the Digitalmars-d-learn
mailing list