Default values in passing delegates to functions

Anonamoose joshuamlewis2 at gmail.com
Wed Jun 23 16:16:53 UTC 2021


I have a script in which I want a special case where someone can 
input something like a potential or a dispersion relation for use 
in physics simulations. I want to clean up the implementation for 
users as not every situation requires these. So I wrote a 
function with the signature

``` d
void myFunc(Function initialFunc, int timeSteps, double 
initialTime, double finalTime, int depth,
     double delegate(double, double) source = &nullSource, double 
delegate(double, double) spacialDispersion = &identitySource, 
bool userOutput = false) {...}
```
where
```d
static double nullSource(double a, double b) {
     return(0);
}
static double identitySource(double a, double b) {
     return(1.0);
}
```

Is this a good method of implementation? Or should I be doing 
this in a completely different way? I am not extremely new to D, 
however, I am new  to using some of the more unique and advanced 
features. Any help or advice is appreciated.


More information about the Digitalmars-d-learn mailing list