Container Array

Vino.B via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 7 23:21:56 PDT 2017


On Thursday, 7 September 2017 at 20:47:43 UTC, Ali Çehreli wrote:
> On 09/07/2017 10:39 AM, Vino.B wrote:
>
> > Array!(Tuple!(string, ulong)) coSizeDirList () {
>
> You stated the return type explicitly above.
>
> >             return tuple (dFiles[], Subdata[]);
>
> According to the error message, what is being returned does not 
> have the same type:
>
> > Test1.d(27): Error: cannot implicitly convert expression
> > (tuple(dFiles.opSlice(), Subdata.opSlice())) of type
> > Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) to
> > Array!(Tuple!(string, ulong))
>
> The actual return type is
>
>     Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong))
>
> There needs to be some transformations to match the two.
>
> Ali

Hi Ali,

   At last was able to print the output, but i am getting some 
"Deprecation" warnings like below and also can you help me in 
formating the output to display ulong.

Output:
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
Size.d(9): Deprecation: std.container.array.RangeT(A) is not 
visible from module Size
[Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\dir1"), 
Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND3"), 
Tuple!string("C:\\Temp\\sapnas2\\BACKUP\\DND5")][34, 4]

Program:
import std.algorithm: filter, map, fold;
import std.container;
import std.file: SpanMode, dirEntries, isDir;
import std.stdio: File, writefln, writeln;
import std.typecons: tuple, Tuple;
import std.parallelism: parallel;
import std.conv;
import std.range;
Tuple!(RangeT!(Array!(Tuple!string)), RangeT!(Array!ulong)) 
coSizeDirList () {
	string FFs = "C:\\Temp\\sapnas2\\BACKUP";
	int SizeDir = 1;
	ulong subdirTotal;
	ulong subdirTotalGB;
	Array!(ulong) Subdata;
	auto dFiles = Array!(Tuple!(string)) (dirEntries(FFs, 
SpanMode.shallow).filter!(a => a.isDir).map!(a => tuple(a.name)));
     foreach (d; dFiles[]) {
				auto SdFiles = Array!(Tuple!(ulong)) (dirEntries(d[0], 
SpanMode.depth).map!(a => tuple(a.size)));
				foreach(f; SdFiles[]) { subdirTotal += f.fold!((a, b) => a + 
b); }
					subdirTotalGB = (subdirTotal/1024/1024);
					if (subdirTotalGB > SizeDir) { Subdata ~= subdirTotalGB; }
					subdirTotal = 0;
		    }
			return tuple (dFiles[], Subdata[]);
}

void main () {
	writeln(coSizeDirList[]);
	//writefln("%(%-(%-63s %)\n%)", coSizeDirList[]);
}


More information about the Digitalmars-d-learn mailing list