Function Template for Dynamic Parameter
Timoses
timosesu at gmail.com
Fri Jul 6 10:55:06 UTC 2018
On Thursday, 5 July 2018 at 16:23:36 UTC, vino.B wrote:
> Hi All,
>
> Request your help on the below code
>
> auto coCleanFiles(T ...) (T FFs) {
> auto dFiles = Array!(Tuple!(string,
> SysTime))(dirEntries(FFs, SpanMode.depth).map!(a =>
> tuple(a.name, a.timeCreated)));
> return dFiles;
> }
>
> void process(T)(T pfunction, Array!string Dirlst) {
> alias wlsType = typeof(pfunction(T));
> auto Result = taskPool.workerLocalStorage!wlsType();
> foreach (FFs; parallel(Dirlst[],1)) { Result.get ~=
> pfunction(FFs); }
> foreach(i; Result.toRange) { writeln(i[][]); }
> }
>
> void main() {
> Array!string Cleanlst;
> Cleanlst.insert("C:\\Temp\\BACKUP1");
> process(&coCleanFiles, Cleanlst);
> }
>
> Error : Error: coCleanFiles(T...)(T FFs) is not an lvalue and
> cannot be modified
I guess since in above code `coCleanFiles` is a template, you can
not simply take the address of that function template. You'd have
to instantiate the template first
process(&coCleanFiles!string, ...)
If you want to pass the template to process you could define
process as something like
void process(alias func)(Array!string Dirlst)
{
func!string(Dirlst[0]);
}
and call
process!coCleanFiles(Cleanlst);
More information about the Digitalmars-d-learn
mailing list