foonathan / type_safe

Zero overhead utilities for preventing bugs at compile time
https://type_safe.foonathan.net
MIT License
1.53k stars 122 forks source link

Add long += int etc. #105

Closed philipp2100 closed 4 years ago

philipp2100 commented 4 years ago

I think you could allow these operations, especially since long = long + int is already allowed.

Another step would be to allow long = int + unsigned, for example, if long is guaranteed to hold the result. But I understand that this would change the current concept of the library, so probably this should have to be explicitly enabled. Btw., I don't understand why checked arithmetics are not the default. Maybe, this and the letter could be considered together, as part of an approach to have the safest possibility as the default and allow more operations or less checks if explicitly desired.

Anyway, good job! Thanks!

foonathan commented 4 years ago

I think you could allow these operations, especially since long = long + int is already allowed.

That was indeed a bug that it didn't work, fixed now.

Another step would be to allow long = int + unsigned, for example, if long is guaranteed to hold the result. But I understand that this would change the current concept of the library, so probably this should have to be explicitly enabled.

I really don't want to allow too many conversions.

Btw., I don't understand why checked arithmetics are not the default.

This library is mostly about type safety, so a ts::integer should be a type-safe version of int. The checked arithmetic was just a nice convenience feature you can get anyway but it is not the default.