Live data from Hacker News

Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds

bitbucket.org

1–10 of 130 posts

Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds

#3
> bounded::integer uses built-in integers as the template parameter to determine its bounds. This means that it cannot store an integer larger than an unsigned 64-bit or unsigned 128-bit integer (depending on the platform) or smaller than a signed 64-bit or signed 128-bit integer. This restriction should be removed at some point in the future.

So when an overflow happens here I assume it's a compile time error (UB due to integer overflow in constexpr context must be diagnosed by the compiler). A handful of multiplications can get you there easily.

Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds

#4

> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'

Or “mostly” ;)

Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds

#5

> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'

If you work with formal verification this is a pretty common sight.

Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds

#6

> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'

const std::string unusable = "unsuitable";

Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds

#7

> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'

I agree with that statement. How can you use type when you don't know range of values. I want to store year. From 1850 to 2050. What type should I choose? I want to store colour value: from 0 to 2^24-1. What type should I choose?

Re: Bounded Integer: Header-only C++ library replaces integers, adds explicit bounds

#10
post #5

> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable because of the lax requirements on bounds. This must be some new definition of the word 'unusable.'

If you work with formal verification this is a pretty common sight.

If you work with smaller embedded systems and you need portability this is also a common sight (when you also quote the part about cstdint, which most embedded people will be happy with).
Post reply on HN