Non-negative integer types

This is pretty much exactly what I'd like to see eventually. It would "just work" and would trivially have niche value optimization, which is a great benefit to top it off. If I could implement it in user code, I would, but it's simply not possible.

2 Likes

If you felt like taking on a(nother) project, I think the first plausible lang step here is actually figuring out how to have compile-time unbounded integers for use in const generics.

Right now you have to pick which limited-size integer type to use, and for a bunch of stuff there just isn't a good answer. It would be really cool to not have to choose for things that aren't runtime values anyway. And that'd be useful & stabilizable independently from the bigger project of ranged integers.

Proper ranged integers is on my list of things to do, but it's quite low priority.

I actually don't think it would be terribly difficult to have unbounded integers in const generics. The parser already handles any number of digits, and the compiler has a bigint type (as library code).

Do you have any example code that uses it?

That uses what?

Sorry, I should have been more clear. Have you written anything that uses deranged?

I have experimentally used it with time, but nothing that was ever committed or published.