www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Pass lambda into template

reply Andrey <saasecondbox yandex.ru> writes:
Hello,

Here is a code with comments: https://run.dlang.io/is/BNl2Up.

I don't understand how to pass lambda into template.
I get an error:
onlineapp.d(18): Error: template instance `qwerty!((i) => "arg" 
~ i.to!string ~ "[0] == '?'", "||")` cannot use local __lambda1 
as parameter to non-global template qwerty(alias mapper, alias 
delimiter)
Sep 03 2018
next sibling parent Andrea Fontana <nospam example.com> writes:
On Monday, 3 September 2018 at 09:09:44 UTC, Andrey wrote:
 Hello,

 Here is a code with comments: https://run.dlang.io/is/BNl2Up.

 I don't understand how to pass lambda into template.
 I get an error:
onlineapp.d(18): Error: template instance `qwerty!((i) => "arg" 
~ i.to!string ~ "[0] == '?'", "||")` cannot use local __lambda1 
as parameter to non-global template qwerty(alias mapper, alias 
delimiter)
Not the best solution, but did you try to make querty template global adding a third parameter to pass count? Andrea
Sep 03 2018
prev sibling next sibling parent Paul Backus <snarwin gmail.com> writes:
On Monday, 3 September 2018 at 09:09:44 UTC, Andrey wrote:
 Hello,

 Here is a code with comments: https://run.dlang.io/is/BNl2Up.

 I don't understand how to pass lambda into template.
 I get an error:
onlineapp.d(18): Error: template instance `qwerty!((i) => "arg" 
~ i.to!string ~ "[0] == '?'", "||")` cannot use local __lambda1 
as parameter to non-global template qwerty(alias mapper, alias 
delimiter)
Congratulations, you've run into one of D's oldest and most annoying known bugs, issue 5710: https://issues.dlang.org/show_bug.cgi?id=5710 The solution is to define `qwerty` outside of `exec`, and add an additional parameter to pass in `count`: https://run.dlang.io/is/VTeizm
Sep 03 2018
prev sibling parent vit <vit vit.vit> writes:
On Monday, 3 September 2018 at 09:09:44 UTC, Andrey wrote:
 Hello,

 Here is a code with comments: https://run.dlang.io/is/BNl2Up.

 I don't understand how to pass lambda into template.
 I get an error:
onlineapp.d(18): Error: template instance `qwerty!((i) => "arg" 
~ i.to!string ~ "[0] == '?'", "||")` cannot use local __lambda1 
as parameter to non-global template qwerty(alias mapper, alias 
delimiter)
Try this: if(mixin(qwerty!((int i) => "arg" ~ i.to!string ~ "[0] == '?'", "||")))
Sep 03 2018