3 ms·
> you don't pay for what you don't use > throwing an exception on overflow or clamping the value to the minimum or maximum are also possible by use of template
by tom_mellior 7y ago
> you don't pay for what you don't use
> throwing an exception on overflow or clamping the value to the minimum or maximum are also possible by use of template policies (and those particular use cases are already built in to the library)
> Never perform a run-time check when a static check would work instead
... but sometimes do run-time checks?
> Have no space or time overhead
This is a very confusing set of claims. You can't have all of these at the same time. Dynamic checks will be needed more often than you'd think, even in cases that "we" can tell won't overflow, so you'll definitely pay for stuff that you use even though with a stronger system you wouldn't need to use it.
For example, I'm wondering if this system can eliminate dynamic checks in cases like these:
int sum = 0;
for (int i = 0; i < 10; i++) {
sum += i;
}
After this loop sum's type should be integer<55, 55>, but I'd bet (without having tried) that with this actual system it's inferred to integer<0, infinity> and you'd get dynamic checks. Unless you use the "null policy", in which case you don't need this library at all.
There is definitely a case to be made for a system that tries to trap overflows but also tries to use static analysis to be smart about where to put the dynamic checks. But I don't think this system is that.