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:23:42 PDT 2015


On Friday, 9 October 2015 at 07:20:43 UTC, John Colvin wrote:
> 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.

ugh, didn't see other people had posted the same response, the 
thread got split...


More information about the Digitalmars-d mailing list