October 12, 2015
On Monday, 12 October 2015 at 16:34:09 UTC, Andrei Alexandrescu wrote:
> On 10/12/15 11:20 AM, Per Nordlöw wrote:
>> On Friday, 9 October 2015 at 02:41:50 UTC, Timothee Cour wrote:
>>> of course this doesn't work:
>>> auto b=iota(ubyte(0), ubyte(256));
>>> //cannot implicitly convert expression (256) of type int to ubyte
>>
>> What about adding an overload supporting
>>
>>      iota!ubyte(0, 256)
>
> We can add iota!T() with no arguments that spans the entire range of T (integral). -- Andrei

Nice, that'll also be consistent with uniform!T().
October 12, 2015
On 10/12/15 11:51 PM, Nordlöw wrote:
> On Monday, 12 October 2015 at 20:39:11 UTC, Andrei Alexandrescu wrote:
>>> Alexandrescu wrote:
>>>> We can add iota!T() with no arguments that spans the entire range of T
>>>> (integral). -- Andrei
>
>  From a quick glance I couldn't find a way to reuse the existing
> overloads. Can anybody come with a reusing solution?

One possibility (can't look at the code now) is to change the implementation to use a closed interval for state, then use that. But then you still need to mind overflow. Whole range is just a bit special like that. -- Andrei
October 12, 2015
On Mon, Oct 12, 2015 at 1:41 PM, Andrei Alexandrescu via Digitalmars-d < digitalmars-d@puremagic.com> wrote:

> On 10/12/15 10:55 PM, Timothee Cour via Digitalmars-d wrote:
>
>> that's only a partial fix:
>> I also would like to express:
>>
>> iotaInclusive(1,256)
>>
>
> iota!ubyte.drop(1)
>
> iotaInclusive(1,256,3)
>>
>
> iota!ubyte.drop(1).stride(3)
>

That's not a good workaround; it's error-prone in more general cases:

auto fun(ubyte a, ubyte stride){
// return iotaInclusive(a,256, stride);// simple
// error prone with your suggestion:
auto b=some function of a, stride;
return iota!ubyte.drop(b).stride(stride);
}



>
> Just playing devil's advocate.
>
>
> Andrei
>
>


October 12, 2015
On Monday, 12 October 2015 at 20:51:40 UTC, Nordlöw wrote:
> On Monday, 12 October 2015 at 20:39:11 UTC, Andrei Alexandrescu wrote:
>>> Alexandrescu wrote:
>>>> We can add iota!T() with no arguments that spans the entire range of T
>>>> (integral). -- Andrei
>
> From a quick glance I couldn't find a way to reuse the existing overloads. Can anybody come with a reusing solution?

Wouldn't it be enough changing the overload

auto iota(E)(E end)

to

auto iota(E)(E end = E.max)

?

October 12, 2015
On 10/12/2015 10:51 PM, Nordlöw wrote:
> On Monday, 12 October 2015 at 20:39:11 UTC, Andrei Alexandrescu wrote:
>>> Alexandrescu wrote:
>>>> We can add iota!T() with no arguments that spans the entire range of T
>>>> (integral). -- Andrei
>
>  From a quick glance I couldn't find a way to reuse the existing
> overloads. Can anybody come with a reusing solution?

auto iota(T)(){
    import std.range;
    return chain(iota(T.min,T.max),only(T.max));
}

void main(){
    import std.stdio;
    writeln(iota!byte());
    writeln(iota!dchar());
}
October 12, 2015
On 10/12/2015 11:52 PM, Jacques Müller wrote:
> On Monday, 12 October 2015 at 20:51:40 UTC, Nordlöw wrote:
>> On Monday, 12 October 2015 at 20:39:11 UTC, Andrei Alexandrescu wrote:
>>>> Alexandrescu wrote:
>>>>> We can add iota!T() with no arguments that spans the entire range of T
>>>>> (integral). -- Andrei
>>
>> From a quick glance I couldn't find a way to reuse the existing
>> overloads. Can anybody come with a reusing solution?
>
> Wouldn't it be enough changing the overload
>
> auto iota(E)(E end)
>
> to
>
> auto iota(E)(E end = E.max)
>
> ?
>

No.

import std.range;
writeln(iota(byte.max));

starts at 0
 |
 v
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37,
38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73,
74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107,
108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
122, 123, 124, 125, 126]
                     ^
                     |
               ends before 127
October 12, 2015
On 10/12/2015 11:02 PM, Vladimir Panteleev wrote:
> On Monday, 12 October 2015 at 16:34:09 UTC, Andrei Alexandrescu wrote:
>> On 10/12/15 11:20 AM, Per Nordlöw wrote:
>>> On Friday, 9 October 2015 at 02:41:50 UTC, Timothee Cour wrote:
>>>> of course this doesn't work:
>>>> auto b=iota(ubyte(0), ubyte(256));
>>>> //cannot implicitly convert expression (256) of type int to ubyte
>>>
>>> What about adding an overload supporting
>>>
>>>      iota!ubyte(0, 256)
>>
>> We can add iota!T() with no arguments that spans the entire range of T
>> (integral). -- Andrei
>
> Nice, that'll also be consistent with uniform!T().

As will iota!"[]".
October 13, 2015
On Monday, 12 October 2015 at 13:17:32 UTC, Timon Gehr wrote:
> On 10/09/2015 04:41 AM, Timothee Cour via Digitalmars-d wrote:
>>
>> Could we have a function with iota_inclusive that has inclusive bounds
>> for 'end' parameter ?
>>
>
> iota!"[]" ?

Yes please.
1 2 3
Next ›   Last »