[Issue 13370] New: Allow @nogc delegates in foreach
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Sun Aug 24 09:19:27 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=13370
Issue ID: 13370
Summary: Allow @nogc delegates in foreach
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: sfrijters at gmail.com
Currently, an opApply function cannot be @nogc:
struct NumberRange {
int begin;
int end;
int opApply(int delegate(ref int) @nogc operations) @nogc const
{
int result = 0;
for (int number = begin; number != end; ++number) {
result = operations(number);
if (result) {
break;
}
}
return result;
}
}
void main() {
import std.stdio;
foreach (element; NumberRange(3, 7)) { // line 21
write(element, ' ');
}
}
When compiled with 2.066.0:
opapply.d(21): Error: function opapply.NumberRange.opApply (int
delegate(ref int) @nogc operations) const is not callable using
argument types (int delegate(ref int __applyArg0) @system)
It would be nice if this code could be allowed, preferably by inference,
otherwise by allowing something like
foreach (element; NumberRange(3, 7) @nogc) { ... }
Discussion here:
http://forum.dlang.org/thread/fqaskxirvcxrdevmacdo@forum.dlang.org
--
More information about the Digitalmars-d-bugs
mailing list