On Wednesday, 27 January 2016 at 08:48:20 UTC, Mathias Lang wrote:
2016-01-27 8:10 GMT+01:00 rsw0x via Digitalmars-d < [email protected]>:

[...]


For delegate you can use `scope delegate`, which is stack-allocated. Using a sink-based approach like `toString` that specific point is quite
easily solved.
`scope` safety being unimplemented, it's also quite easy to abuse if you
don't have control over the function decl:

```
import core.stdc.stdio;
void main () @nogc
{
    string foobar = "Value";
    scope sink = (int u) { printf("%s: %d\n", foobar.ptr, u); };
    foo(sink);
}

void foo (void delegate (int) @nogc sink) @nogc
{
    sink(42);
}
```
Alternatively, you can make foo's parameter `scope` and use the literal
inline, it's recognized by @nogc.

This is not applicable in a scenario where I want to actually copy the parameters by value. It still captures the context, it just allows it to move down the stack.

Reply via email to