Weird issue with std.range.iota.length

Dominikus Dittes Scherkl via Digitalmars-d digitalmars-d at puremagic.com
Sun Feb 14 23:59:57 PST 2016


On Sunday, 14 February 2016 at 13:16:58 UTC, Jonathan M Davis 
wrote:
> On Sunday, 14 February 2016 at 10:59:41 UTC, w0rp wrote:
>> Maybe I'm missing something, but can't the length just be 
>> size_t? I doubt there is much you could do with code which 
>> generates finite sequences larger than the addressable memory 
>> space, aside from very abstract and inefficient mathematical 
>> calculations which skip over elements. iota would probably 
>> work better with size_t in most cases, and if you really well 
>> and truly need something which generates finite sequences of 
>> integers larger than the addressable memory space, you can 
>> always just write your own version.
>
> Yeah. It would be easy enough to just make iota size_t and then 
> have it check the actual length of the range when it's called 
> to make sure that it's not larger than will fit in size_t (and 
> presumably throw a RangeError if the number of elements is too 
> large). Anyone who really wants to have a range with more than 
> size_t.max elements can write their own thing. It's not like 
> it's going to work nicely with other ranges anyway - at least 
> not as long as it defines length.
>
> - Jonathan M Davis

+1


More information about the Digitalmars-d mailing list