New data type idea: counter

A counter is just a binary value that increments up and is to be called locally.

Why is this useful? It saves more space than an integer and it's only purpose it to keep track of how many times something has happened, such as a recursion loop.

Is this acheivable already. Yes, literally just use an int instead. Does it save space and is it more optimised? In theory, yes, as it is binary and only ever increments up by one the program already knows how it will operate, it's deterministic in a way other variables are not.

How many bytes would this type be?

You do realize that an integer (i8/u8, i16/u16, i32/u32, i64/u64) are all binary right? They are not decimal representations like BCD (Binary Coded Decimal). Are you thinking they are BCD and so they waste bits? That is not the case.

2 Likes

We have one; it's called RangeFrom<_> :slight_smile:

(Or, soon, IterRangeFrom in std::range - Rust)