Range Type

Don Clugston dac at nospam.com.au
Wed Mar 26 04:46:02 PDT 2008


renoX wrote:
> Janice Caron a écrit :
>> On 24/03/2008, Craig Black <cblack at ara.com> wrote:
>>> Why would the type T and U ever be different?  What's the point of the
>>>  second type being different than the first?
>>
>> Um ... I have no idea. I guess it's just to be consistent with the
>> fact that we can already declare:
>>
>>     opSlice(T lower, U upper)
>>
>> with T and U being different. Maybe someone will find a use for it one
>> day. That said, it does at least allow you to use ".." in
>> declarations, as in:
>>
>>     int..int x;
>>     x = 3..4;
>>
>> and you have to admit, T..T is likely to be less typing (and look
>> prettier) than Range!(T). :-)
> 
> Well, most range will probably be integer range, so if we could define
> Range! to be Range!(int) by default then it would be even less typing 
> than int..int.
> 
> Shouldn't we plan an optional 'step' parameter now?

Definitely not.
Consider floating point ranges. What 'step' do you use?
1..1e10
You can step linearly (1,2,3...), logarithmically(1, 1e2, 1e3...) or in IEEE 
space. (1, nextUp(1), nextUp(nextUp(1)), ....)
There are just too many reasonable options. Once steps are involved, you need a 
generator.
But ranges are simple.



More information about the Digitalmars-d mailing list