Have you tried Ada?
Re:Dense bitpacking
by nickpsecurity on Saturday August 08, 2015 @11:08PM
(#10029371)
Ada solved a lot of problems that show up on SO, HN, etc a while ago. Mature tools, too. Yet, the mainstream preference is that Ada is hard and ugly to use but trying to re-invent Ada in existing languages is easier. Doesn't sound easier... ;)
All of these are things that you can do manually, and that you can leave to the compiler and hope that it'll pick the correct one, but currently good luck telling the compiler that no, you really actually want to do <x>. Or to try <x> and <y> and see which is better. And the amount of time required to do so manually adds up, even though they are all things that could be done by a compiler.
I personally wish that you could specify / annotate the range that you are actually intending to store in an integer (and have it optionally bound-checked) anyway, but that is another matter.
(Actually, I wish that you could specify types with an arbitrary (probably-pure) boolean function to indicate if something is or isn't a valid value in the type. But that is another matter indeed.)