Check whether a range is empty

vino.B bheeman.vino at hotmail.com
Sun Jul 15 11:45:10 UTC 2018


On Saturday, 14 July 2018 at 17:20:52 UTC, Ali Çehreli wrote:
> First, please show us code that demonstrates the issue.
>
> On 07/14/2018 07:47 AM, vino.B wrote:
>
> >    The reason it never prints the text "Empty" is that the
> out of the
> > "r" is just an empty array.
> >
> > OUTPUT:
> > []
> > []
>
> If that's the output of r, then r is not empty but has two 
> elements and those elements are likely arrays. If they are in 
> fact arrays, them being empty does not change r: it still has 
> two elements.
>
> If you want to treat the range as empty when all its elements 
> are empty, then perhaps your problem needs 
> std.algorithm.joiner. The following program demonstrates your 
> issue with the first assert and the fix with the second assert:
>
> import std.algorithm;
> import std.range;
>
> void main() {
>     int[][] r = [ [], [] ];
>     assert(!r.empty);
>     auto joined_r = r.joiner;
>     assert(joined_r.empty);
> }
>
> joiner joins elements that are ranges themselves. For example, 
> joiner([ [1], [2] ]) is equal to [ 1, 2 ].
>
> Ali

HI Ali,

  Thank you very much, but unfortunately the above solution did 
not work as the variable PFResult contains the output from the 
workerLocalStorgage which is prited as PFResult.toRange , but was 
able to find a solution as below

void ptThreadManager(alias coRoutine, T...)(Array!string Dirlst, 
T params)
{
       alias scRType = typeof(coRoutine(string.init, T.init));
       auto PFresult = taskPool.workerLocalStorage!scRType();
       PFresult.get ~= coRoutine(FFs, params); }
       int a = 0;
       if (!(PFresult.toRange).empty) {
       foreach(i; chain(PFresult.toRange)) { writeln(i[]); a = a 
+1;} }
       if(a == 0) { writeln("No files");

}

From,
Vino.B




More information about the Digitalmars-d-learn mailing list