<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-01-27 8:10 GMT+01:00 rsw0x via Digitalmars-d <span dir="ltr"><<a href="mailto:digitalmars-d@puremagic.com" target="_blank">digitalmars-d@puremagic.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">I have to manually create my own functors to be able to capture variables by value in lambdas so that they're usable in @nogc. How C++98.<br>
Alias template parameters are again massive hidden abusers of the GC.</blockquote><div><br></div><div>For delegate you can use `scope delegate`, which is stack-allocated.<br>Using a sink-based approach like `toString` that specific point is quite easily solved.<br>`scope` safety being unimplemented, it's also quite easy to abuse if you don't have control over the function decl:<br><br>```<br><div>import core.stdc.stdio;</div><div>void main () @nogc</div><div>{</div><div>    string foobar = "Value";</div><div>    scope sink = (int u) { printf("%s: %d\n", foobar.ptr, u); };</div><div>    foo(sink);</div><div>}</div><div><br></div><div>void foo (void delegate (int) @nogc sink) @nogc</div><div>{</div><div>    sink(42);</div><div>}</div>```</div><div>Alternatively, you can make foo's parameter `scope` and use the literal inline, it's recognized by @nogc.</div></div></div></div>