| Thread overview | |||||
|---|---|---|---|---|---|
| 
 | 
| January 14, 2021How to define delegate with needed parameters | ||||
|---|---|---|---|---|
| 
 | ||||
| I would like to be able to create a delegate but also supply the function parameters to be used for the function call. How can I go about doing this? Example:
void foo(int i){
}
void bar(string m){
}
doSomething(&foo(q));
doSomething(&bar("test");
 | ||||
| January 14, 2021Re: How to define delegate with needed parameters | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to Tim | On Thursday, 14 January 2021 at 00:19:24 UTC, Tim wrote:
> I would like to be able to create a delegate but also supply the function parameters to be used for the function call. How can I go about doing this? Example:
>
> void foo(int i){
> }
>
> void bar(string m){
> }
>
> doSomething(&foo(q));
> doSomething(&bar("test");
Easiest way is to use a lambda:
doSomething(() => foo(q))
 | |||
| January 14, 2021Re: How to define delegate with needed parameters | ||||
|---|---|---|---|---|
| 
 | ||||
| Posted in reply to Paul Backus | On Thursday, 14 January 2021 at 00:29:23 UTC, Paul Backus wrote:
> Easiest way is to use a lambda:
>
> doSomething(() => foo(q))
This worked perfectly, thank you for your timely response~
 | |||
Copyright © 1999-2021 by the D Language Foundation
  Permalink
Permalink Reply
Reply