how to do iota(0,256) with ubytes ? (cf need for iotaInclusive)
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Fri Oct 9 00:20:41 PDT 2015
On Friday, 9 October 2015 at 02:41:50 UTC, Timothee Cour wrote:
> how to do iota(0,256) with ubytes ?
> and more generally:
> iota with 'end' parameter set to max range of a type.
>
> of course this doesn't work:
> auto b=iota(ubyte(0), ubyte(256));
> //cannot implicitly convert expression (256) of type int to
> ubyte
>
> Could we have a function with iota_inclusive that has inclusive
> bounds for 'end' parameter ?
A bounds parameter would be nice, like in std.random.uniform.
For anyone googling for a solution to this, here's a workaround:
auto b = iota(0, 256).map!"cast(ubyte)a";
Unfortunately this doesn't scale to iterating over all values of
long or ulong.
More information about the Digitalmars-d
mailing list