www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - StoppingPolicy.longest never stop?

reply tsukikage <tsukikage dmail.com> writes:
Why this zip not stop after iterated through the longest range? thanks!

import std.stdio, std.range ;
void main() {
     auto a = [1,2,3,4] ;
     auto b = [6,7,8,9] ;
     auto c = "ABCDE" ;   // <= longest range here
     auto d = "ZYXW" ;
     auto CNT = 0 ;
     foreach(p; zip(StoppingPolicy.longest, a,b,c, d))
         if(CNT++ < 30)
             writefln("%s %s %s %s", p[0],p[1],p[2], p[3]) ;
         else
             break ;
}

output:
1 6 A Z
2 7 B Y
3 8 C X
4 9 D W
0 0 E ￿
0 0 ￿ ￿
0 0 ￿ ￿ <= this continue infinitely if not supply a stopping
_CNT_
Jan 29 2011
parent reply tsukikage <tsukikage dmail.com> writes:
tsukikage wrote:
 Why this zip not stop after iterated through the longest range? thanks!
 
 import std.stdio, std.range ;
 void main() {
     auto a = [1,2,3,4] ;
     auto b = [6,7,8,9] ;
     auto c = "ABCDE" ;   // <= longest range here
     auto d = "ZYXW" ;
     auto CNT = 0 ;
     foreach(p; zip(StoppingPolicy.longest, a,b,c, d))
         if(CNT++ < 30)
             writefln("%s %s %s %s", p[0],p[1],p[2], p[3]) ;
         else
             break ;
 }
 
 output:
 1 6 A Z
 2 7 B Y
 3 8 C X
 4 9 D W
 0 0 E ￿
 0 0 ￿ ￿
 0 0 ￿ ￿ <= this continue infinitely if not supply a stopping
_CNT_
note: ￿ is 0xffff (wchar init?) print as "%s"
Jan 29 2011
parent reply bearophile <bearophileHUGS lycos.com> writes:
tsukikage:

 Why this zip not stop after iterated through the longest range? thanks!
http://d.puremagic.com/issues/show_bug.cgi?id=5506 Bye, bearophile
Jan 30 2011
parent tsukikage <tsukikage dmail.com> writes:
bearophile wrote:
 tsukikage:
 
 Why this zip not stop after iterated through the longest range? thanks!
http://d.puremagic.com/issues/show_bug.cgi?id=5506 Bye, bearophile
Thank you!
Jan 30 2011