Ranges longer than size_t.max

Jonathan M Davis jmdavisProg at gmx.com
Sat Dec 29 01:20:29 PST 2012


On Saturday, December 29, 2012 10:00:44 Peter Alexander wrote:
> On Saturday, 29 December 2012 at 03:28:47 UTC, Andrei
> 
> Alexandrescu wrote:
> > On 12/28/12 9:21 PM, Peter Alexander wrote:
> >> I'm already assuming 64-bit. What I'm saying is that 64-bit
> >> sometimes
> >> isn't even enough (for example in the case of a permutations
> >> range). I'm
> >> asking if allowing length to return BigInt would be reasonable.
> > 
> > I think it would complicate a lot of things for the benefit of
> > a few cases.
> 
> I agree, but the range of permutations will be longer than 2^64
> on occasion, so what do we do?
> 
> * Don't provide .length at all
> * Provide it as size_t, and assert on overflow
> * Provide it as size_t, and silently overflow

I expect that it'll be silently overflow in most cases, because that's a lot 
simpler and the problem is almost never an issue. It also incurs a performance 
penalty in non-release mode where there's almost never any benefit from it. But 
if you want to provide pull requests with assertions for overflow in various 
Phobos algorithms, then they'll probably be merged in.

- Jonathan M Davis


More information about the Digitalmars-d mailing list