I wish all qualifiers were revisited with an eye for simplification

Timon Gehr timon.gehr at gmx.ch
Mon Aug 24 20:10:49 UTC 2020


On 24.08.20 19:19, Steven Schveighoffer wrote:
>>
> 
> I'm not sure what you mean -- inout is like const in that you cannot 
> mutate data via that reference.

With a better type system the caller might pass in delegates that know 
about the mutability.

void foo[Qualifier q](ref q int x, void delegate(ref q int x) process){
     process(x);
}

void main(){
     int x=0;
     foo(x,(ref int a){ a=2; }); // (q is mutable)
     immutable int y=2;
     foo(y,(ref immutable int b){ x=b; }); // (q is `immutable`)
}



More information about the Digitalmars-d mailing list