how to do iota(0,256) with ubytes ? (cf need for iotaInclusive)

Adam D. Ruppe via Digitalmars-d digitalmars-d at puremagic.com
Thu Oct 8 20:51:38 PDT 2015


On Friday, 9 October 2015 at 02:44:19 UTC, Timothee Cour wrote:
> also, workarounds involving:
> iota(0,256).map!(a=>cast(ubyte)a)
> are neither pleasant nor efficient

There's no difference in efficiency since that's how it'd 
probably be done on the low level anyway (assuming the compiler 
inlines it at least).

I suppose it could also be written something like

xor al, al;
again:
  // stuff here
inc al;
jnc again;


But I doubt there'd be a real performance difference between that 
and the int compare+cast version anyway.


I think the way you did it there is one of the better options. If 
you don't like how it looks, just wrap it in a little function so 
you only have to look at it once.

If you want it in phobos, you could submit the function for there 
too in a pull request.



More information about the Digitalmars-d mailing list