Passing Function as an argument to another Function
Ali Çehreli
acehreli at yahoo.com
Mon Dec 4 19:25:15 UTC 2017
On 12/04/2017 04:52 AM, Vino wrote:
> if the Variable CleanDirlst is defined as "auto"
Every expression has a type. 'auto' in that context (or 'const', etc.)
just helps with not spelling-out that type. You can see the type with
pragma(msg) and typeof:
auto someExpression = [ "one" : 1, "two" : 2 ];
pragma(msg, typeof(someExpression)); // Prints int[string]
> can we define "auto" as below(auto Dirlst).
> void ptProcessFiles() (auto Dirlst, Array!(Tuple!(string, string))
> function(string, string, int) coRoutine, File logF, File logE, string
> Step, int Aged)
You can use templates. Here is my introduction to the concept:
http://ddili.org/ders/d.en/templates.html
However, in this case a simple 'alias' will do:
alias MyListType = int[string];
void foo(MyListType arg) {
// ...
}
> Q2 :
> How do we define an "auto" function(auto function(string, string, int)
> coRoutine)
> void ptProcessFiles() (auto Dirlst, auto function(string, string, int)
> coRoutine, File logF, File logE, string Step, int Aged)
alias helps in that case as well:
alias MyCoRoutineType = MyListType function(string, string, int);
void ptProcessFiles(MyListType Dirlst, MyCoRoutineType coRoutine, File
logF, File logE, string Step, int Aged) {
// ...
}
Likewise, ptProcessFiles can be a template as well, where the type of
coRoutine can be a template argument but not needed in this case.
Ali
More information about the Digitalmars-d-learn
mailing list