On Wednesday, 13 December 2017 at 15:16:50 UTC, Vino wrote:
Hi All,

Request your help, on how to sort a tuple container array, I have raised the same topic in one of the other thread "Tuple Array Sorting" and was addressed to use standard array rather than container array, and i am not able to find any document or example in the library for the same.

Eg: Program.
import std.algorithm: filter, map, sort;
import std.container.array;
import std.file: SpanMode, dirEntries, isDir ;
import std.stdio: writeln;
import std.typecons: Tuple, tuple;
import std.datetime.systime: SysTime;

void main () {
auto FFs =  ["C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir)
        .sort!((a,b) => a.timeCreated > b.timeCreated)
        .map!(a => tuple(a.name, a.timeCreated)));
writeln(dFiles[]);
} }

From,
Vino.B

HI All,

As per the message from the below forum I understand that that we cannot perform a sorting on filtered result a container array but the same can be performed form the standard array, so i adjusted the above code as below and getting a different error than what is discussed in the forum.

Forum:
"https://forum.dlang.org/post/mcteinnryudlqvbkq...@forum.dlang.org";

Program:
void main () {
auto FFs = ["C:\\Temp\\sapnas2\\BACKUP", "C:\\Temp\\sapnas2\\EXPORT"];
Array!(Tuple!(string, SysTime)) Result;
foreach(d; FFs[]) {
auto dFiles = Array!(Tuple!(string, SysTime))(dirEntries(d, SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name, a.timeCreated)))[]
        .sort!((a,b) => a[1] > b[1]);
writeln(dFiles[]);
} }

Error:
Message.d(14): Error: function Message.main.SortedRange!(RangeT!(Array!(Tuple!(string, SysTime))), __lambda3).SortedRange.opSlice (uint a, uint b) is not callab
le using argument types ()
Failed: ["dmd", "-v", "-o-", "Message.d", "-I."]

From,
Vino.B

Reply via email to