opApply compilation woes

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jul 12 10:39:59 PDT 2015


On Sunday, 12 July 2015 at 17:33:50 UTC, anonymous wrote:
> On Sunday, 12 July 2015 at 17:25:17 UTC, Gary Willoughby wrote:
>> Why does the following code fail to compile if the 
>> `writeln(value);` line is present?
>
> The error message (formatted to be a little more readable):
> ----
> Error: function test2.__unittestL6_1.Foo.opApply
>   (int delegate(ref string) nothrow dg)
> is not callable using argument types
>   (int delegate(ref string __applyArg0) @system)
> ----
>
> Note that the parameter has "nothrow", but the argument 
> doesn't. And that's it: writeln isn't nothrow.

Ah right, because the body of the foreach becomes the body of the 
delegate. Thanks.


More information about the Digitalmars-d-learn mailing list