Boost logo

Boost :

From: degski (degski_at_[hidden])
Date: 2020-02-28 20:15:32

On Fri, 28 Feb 2020 at 17:48, Alexander Grund via Boost <
boost_at_[hidden]> wrote:

> There exists no negative size.

This IS exactly why you should use signed int's, so overflow is easy to
detect. By the time you (I don't mean You of course, sorry for my bad
english) wrapped almost (a little bit less than 2^64) around the
std::size_t integer line, you have no way to figure out if the number is
correct or not (it could be very close, in the right direction and still be
wrong, that's where the problem is), you just don't know, possibly it
wrapped (several times maybe). Finding bugs related to this is hard, using
int's you'll know right away.

> If you get an unsigned
> value there is no need to check for below zero, if you get a signed
> value you might. It is the same there is `not_null<T>` in GSL(?).

 But you would need to check if it wrapped and if you start adding and
subtracting these things (or use Robert's library, but I guess, it does not
all come for free, that safety), you'll need to find in advance whether
it's going to wrap or not (if you do things properly), after the event
you're just staring at a number which in the real world does not mean much.
Nothing wraps in the real world, if things keep growing (like the
world-population) at some point it will say kaboom (the int's should be
sized to requirement of course like OP has implemented, I applaud this, now
it only needs to also be possible to make that signed).

The whole discussion just shows that there is a problem with operations
> mixing signed and unsigned types in C++ in general.

Yes, solution: signed, slightly (a power of 2, :-) ) smaller, but that is
not relevant for actual 'problems' in this (our) world.

What we probably wanted was something like `size_t = not_negative<int>`,
> but well...

I don't understand.


"We value your privacy, click here!" Sod off! - degski
"Anyone who believes that exponential growth can go on forever in a finite
world is either a madman or an economist" - Kenneth E. Boulding
"Growth for the sake of growth is the ideology of the cancer cell" - Edward
P. Abbey

Boost list run by bdawes at, gregod at, cpdaniel at, john at