Header only library for safe integers in C++. The library is found in include/safe_integers.h
.
Using raw integers is dangerous. Just a few examples:
- Signed integer overflow is undefined behavior
- Dividing by zero is undefined behavior
This library allows you to avoid raw integers entirely in your code base. Notice:
- There is no mention of
int
or any other integer type in the library - There are no integer literals in the library either
- There is no ZERO in the library, so it's impossible to divide by zero
assert(ONE + FIVE == SIX);
assert(ONETHOUSAND - THIRTEEN == NINEHUNDREDANDEIGHTYSEVEN);
constexpr auto ONE = +!!"";
constexpr auto TWO = ONE + ONE;
constexpr auto THREE = TWO + ONE;
//(...)
constexpr auto SIXHUNDREDANDTHIRTYNINETHOUSANDNINEHUNDREDANDNINETYNINE = SIXHUNDREDANDTHIRTYNINETHOUSANDNINEHUNDREDANDNINETYEIGHT + ONE;
constexpr auto SIXHUNDREDANDFORTYTHOUSAND = SIXHUNDREDANDTHIRTYNINETHOUSANDNINEHUNDREDANDNINETYNINE + ONE;
// SIXHUNDREDANDFORTYTHOUSAND ought to be enough for anybody
Based on ideas by moonette and Ólafur Waage
Yes, this is a joke.