Issue 19287 - each only accepts lambdas that take a single argument
Summary: each only accepts lambdas that take a single argument
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-05 06:55 UTC by Nicholas Wilson
Modified: 2024-12-01 16:34 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nicholas Wilson 2018-10-05 06:55:35 UTC
See https://forum.dlang.org/post/tgnnsqkclbcaejhbiprn@forum.dlang.org for the motivation.

struct that contain destructors cannot be closed over (I'm not sure why but thats a different problem) and so 

CantCloseMe o; // some struct with a door
somerange.each!(e => foo(o,e)); //Error: variable `o` has scoped destruction, cannot build closure

fails. But it can't be worked around with 
somerange.each!((e,f) => foo(o,f))(o);

Fails with

Error: template somerange.each!((e,f) => foo(o,f)).each cannot deduce function from argument types !()(SomeRange, CantCloseMe), candidates are:
...

because all of the each functions take only a range or iterable.
Comment 1 dlangBugzillaToGithub 2024-12-01 16:34:16 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10352

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB