Foreach/opApply with @nogc
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Aug 24 06:40:30 PDT 2014
On Sun, 24 Aug 2014 13:22:49 +0000
Stefan Frijters via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
@nogc is a part of signature. gc-function can't call @nogc-one. the
same is with calling @system function from @safe one, for example. or
impure function from pure.
so to say, foreach() creates implicit delegate withoit '@nogc'
attribute, that's why compiler complains.
there is currenly no way to specify attributes for such implicit
delegates. this will work, but you'll not be able to call writeln():
nogc:
void main() {
import std.stdio;
foreach (element; NumberRange(3, 7)) { // line 21
//write(element, ' '); // this will fail with
// @nogc function 'z00.main.__foreachbody1' cannot call
// non- at nogc function 'std.stdio.write!(int, char).write'
}
}
what we need here is something like:
foreach (element; NumberRange(3, 7) @nogc) { ... }
but alas...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140824/75a5976f/attachment.sig>
More information about the Digitalmars-d-learn
mailing list