Trouble with lockstep

Craig Dillabaugh cdillaba at cg.scs.carleton.ca
Mon Jun 24 08:22:17 PDT 2013


On Monday, 24 June 2013 at 15:15:46 UTC, bearophile wrote:
> Craig Dillabaugh:
>
>> clip
>
> Most range/algorithm functions unfortunately don't accept a 
> fixes size array. So you have to slice it:
>
> void main() {
>     import std.stdio, std.range;
>
>     ubyte[] data = [17, 32, 32, 32, 38, 39, 39, 47,
>                     47, 47, 47, 109, 111, 111, 128];
>     uint[ubyte.max - ubyte.min + 1] bins;
>
>     foreach (immutable val; data)
>         bins[val]++;
>
>     foreach (uint idx, count; iota(ubyte.min, ubyte.max + 
> 1).zip(bins[]))
>         if (count > 0)
>             writeln("Bin = ", idx, " count = ", count);
> }
>
> Bye,
> bearophile

Thanks.  Now it works, if I use .zip().


More information about the Digitalmars-d-learn mailing list