Function Template for Dynamic Parameter
vino.B
bheeman.vino at hotmail.com
Thu Jul 5 16:23:36 UTC 2018
On Sunday, 1 July 2018 at 12:46:30 UTC, Timoses wrote:
> On Sunday, 1 July 2018 at 11:58:30 UTC, vino.B wrote:
>> On Sunday, 1 July 2018 at 11:52:19 UTC, Alex wrote:
>> NewType.d(19): Error: function declaration without return
>> type. (Note that constructors are always named this)
>>
>> [...]
>>
>> auto coCleanFiles(T ...)(T args) {
>> auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(FFs,
>> SpanMode.shallow).filter!(a => a.isFile).map!(a =>
>> tuple(a.name, a.timeLastModified)));
>> return dFiles;
>> }
>>
>> void ptManagecoRoutine(T)(T function(T ...)(T args),
>> Array!string Dirlst) {
>> alias scRType = typeof(coRoutine(args.init));
>> auto PFresult = taskPool.workerLocalStorage!scRType;
>> ReturnType!coRoutine rData;
>> foreach (string FFs; Dirlst[]) { PFresult.get ~=
>> coRoutine(FFs.strip); }
>> foreach(i; PFresult.toRange) { rData ~= i[][]; }
>> if (!rData[].empty) { rData[].sort!((a,b) => a[1] <
>> b[1]).each!(e => writefln!"%-83s %.20s"(e[0],
>> e[1].to!string)); }
>> }
>> void main () {
>> Array!string CleanDirlst;
>> CleanDirlst.insertBack("C:\\Temp\\BACKUP1");
>> ptManagecoRoutine(&coCleanFiles, CleanDirlst);
>> }
>
>
> auto coCleanFiles(T ...)(T args)
> { ... }
>
> void ptManagecoRoutine(T)(T fun, Array!string DirList)
> {
> foreach (dir; DirList)
> fun(dir);
> }
>
> or
>
> void ptManagecoRoutine2(alias func)(Array!string DirList)
> if (is (typeof(func!(typeof(DirList[0]))) == function))
> {
> alias t = typeof(DirList[0]);
> ptManagecoRoutine(&func!t, DirList);
> }
>
> callable via
>
> Array!string CleanDirlst;
> ptManagecoRoutine(&coCleanFiles!string, CleanDirlst);
> ptManagecoRoutine2!coCleanFiles(CleanDirlst);
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
From,
Vino.B
More information about the Digitalmars-d-learn
mailing list