Live data from Hacker News

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

bitbucket.org

91–100 of 130 posts

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

#91
post #56

Maybe Ada's approach of every number type requiring explicit bounds is a good one.

I think that's a good part of ADA that should have been copied 30 years ago. That and you should be able to define overflow semantics as well.

Ada. It’s not an acronym. ADA is the Americans with Disabilities Act.

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

#92
post #56

Earlier quoted context omitted.

I think that's a good part of ADA that should have been copied 30 years ago. That and you should be able to define overflow semantics as well.

Ada. It’s not an acronym. ADA is the Americans with Disabilities Act.

go away

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

#93
post #92

Earlier quoted context omitted.

Ada. It’s not an acronym. ADA is the Americans with Disabilities Act.

go away

By all means be as imprecise and incorrect as you want, but you can hardly complain when people on a technical forum correct your imprecision ¯\_(ツ)_/¯

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

#94
post #79

Earlier quoted context omitted.

> but with a library like this, it has to make a subroutine call. I mean, before I wrote my comment I checked and it's `constexpr` all the way down to the add instruction so if it's going to make a call, I'm not seeing it. There is definitely a lot of template machinery, but I can't be the judge of that immediately. > I personally feel that libraries like this are taking C++ in the wrong direction ("ranges" is anothe…

constexpr functions are not inlined in debug builds. They can't be: the whole point of debug builds is that you can attach a debugger and step through the code. Illustration, compare the assembly for "foo1" and "foo2": https://godbolt.org/z/t9Zkx-

For what is worth they are optimized out with -Og (if that doesn't count as debug build I don't know what does).

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

#95
post #89
post #56

Earlier quoted context omitted.

I think that's a good part of ADA that should have been copied 30 years ago. That and you should be able to define overflow semantics as well.

It was indeed copied, by Pascal, Turbo Pascal, Delphi, Modula-2, Modula-3, unfortunately not by the languages that won.

Copied from Pascal to Ada, no?

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

#96
post #71

Oh, that's nice. I wanted that decades ago, when I was working on program verification. Templates have made a lot of progress if this can be done entirely in C++ templates. I once wrote, but never published, "Type Integer Considered Harmful", back when there were still 16-bit integers in most C programs. I wanted ranges on everything, like Ada. As a practical matter, integer overflow became less of an issue with 32-b…

This was more or less the source of infamous Turbo Pascal 'Runtime Error 200: Divide by zero', twice! http://ss64.net/merlyn/pas-r200.htm#Why

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

#97
post #92

Earlier quoted context omitted.

go away

By all means be as imprecise and incorrect as you want, but you can hardly complain when people on a technical forum correct your imprecision ¯\_(ツ)_/¯

perhaps the commentor should have specified explicit bounds to their precision.

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

#98
post #84
post #41

Earlier quoted context omitted.

it does not have to. A smart compiler can narrow it down to machine size integers then possible.

> A smart compiler can narrow it down to machine size integers then possible. A smart compiler will be able to narrow it down in a limited set of scenarios, but all we need to do is put an accumulator into a loop to see that bounding an integer is equivalent to the halting problem. Or for another example, should we expect our "smart" compiler to bound y in the following? The bound on x is a freebie. bigint n(uint64_t…

tfw you notice typos after the edit window closes :'(

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

#99
post #30

At this point, when I see libraries like this all I can think is ”oh good, my compile times aren’t long enough, lets make EVERY INTEGER a template”. Also, while I can reasonably beliveve that most of the overhead goes away at -O2 or -O3, this has to just trash performance for debug builds, which is not unimportant.

I don't think you even looked at the library, but from I can tell, debug perf would not be impacted at all.

> I don't think you even looked at the library

That's a variation of "did you even read the article", which the HN guidelines specifically ask users not to post, so please edit those out of your posts. The comment would be just fine without that bit.

https://news.ycombinator.com/newsguidelines.html

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

#100
> The built-in integer types in C++ (int, unsigned, long long, etc.) are mostly unusable

Weird. Ive been programming in C/C++ professionally for over a decade and have been using built-in integer types mostly without issue. Might want to qualify your hyperbole- is it worth reading on?

Post reply on HN