
Edward Diener wrote:
Mathias Gaunard wrote:
Apart from that, wouldn't it be more interestin, when multiplying a bounded_int
by 2, to yield a bounded_int instead of attempting to keep the object with the same constraint? Of course, that only works with bounded_int and not constraints in general. I disagree with this also. The entire idea of a constraint in this library is that the underlying value meets the criteria of the constraint and not that the constraint changes to accomodate a new underlying value.
I have an even more extreme view on this. I don't believe any arithmetic operations should be permitted for constrained numbers. They just don't make sense (would you ever want to add two different days of a month?). There are occasions where you do want to perform an algorithm that does make sense but where arithmetic operations are performed along the way. But in those cases I want to be forced to do an explicit cast to an unconstrained type. I would add that I think the concept of constrained values is tightly linked to the concept of units (by which I mean the concept of wrapping a number type by a meaningful type), as well as the concept of an algebraic type (where you constrain the algebraic operations that can be performed). I would love to see someone put this all together into a single coherent library.