On 02/19/2012 11:27 PM, kenji hara wrote:
I think the 'scope' keyword may resolve issue.
Attributes of lazy parameter in template function belong to caller side.
int foo()(lazy int value) @safe pure /*nothrow*/ { return value(); }
void main() {
int n = foo(10);
// evaluating lazy parameter never break safety and purity of foo.
// (violating nowthrow-ness might be a bug.)
// because the violation belongs to caller side - it is main function.
}
Similarly, scope delegate body always in caller side, so calling it
means temporary exiting to caller side.
void foo(ref inout int x, scope void delegate(ref inout(int)) dg) {
dg(x);
}
void main() {
int a;
foo(a, (ref int x){ x = 10; }); // don't break foo's inout-ness,
so should be allowed
assert(a == 10);
}
How about?
Kenji Hara
If I get you right, then this cannot work in general.
immutable int y=0;
void foo(ref inout int x, scope void delegate(ref inout(int)) dg) {
dg(y); // boom
}