Currently unique expressions can be converted to arbitrary type qualifier.
int * mp = new int(1);
immutable(int)* ip = new int(1);
But, currently we cannot define a function that returns unique expression without pure attribute.
int* foo() pure { return new int(1); }
int * mp = foo(); // OK
immutable(int)* ip = foo(); // OK
int* bar() { return new int(1); }
int * mp = bar(); // OK
immutable(int)* ip = bar(); // NG!
I think it is possible by the subject proposal.
inout(int)* bar1() { return new int(1); }
int * mp = bar1(); // could be possible
immutable(int)* ip = bar1(); // could be possible
inout(int)* bar2() {
inout(int)* p = new int(1);
// <-- propagate expression uniqueness via inout qualifier
return p;
}
int * mp = bar2(); // could be possible
immutable(int)* ip = bar2(); // could be possible
In my thought, there's some assumptions as follows.
1. Unique expressions (eg. new int(1)) could be converted to arbitrary type qualifier, so it should be convertible to inout type.
2. If inout type appears on return type without inout parameter, it would be converted to arbitrary type qualifier without restrictions from function argument types.
My proposal have some pros:
1. Some limitations about inout type qualifier could be lifted.
For example, isInputRange definition would be simplified.
2. Unique expressions could be more useful in D.
By using inout, we can propagate it in function body.
and cons:
1. We should have a way to copy inout objects - eg. qualified postblit feature (DIP49) is necessary.