Re:Bounded Integer: Header-only C++ library replaces integer...
by nitwit005 on Sunday September 29, 2019 @12:22PM
(#21107911)
It does. I personally stick to those exclusively except for for loop index variables.
[ Parent
| on HN ]
Re:Bounded Integer: Header-only C++ library replaces integer...
by vips7L on Sunday September 29, 2019 @12:45PM
(#21108063)
What would be different about loop variables? I don't really write C++.
Re:Bounded Integer: Header-only C++ library replaces integer...
by rleigh on Sunday September 29, 2019 @01:39PM
(#21108408)
I'm assuming here that they would use the `size_type` for the container they are iterating over. Otherwise I'm not sure.
Re:Bounded Integer: Header-only C++ library replaces integer...
by ncmncm on Sunday September 29, 2019 @03:27PM
(#21109132)
An unsigned type is sometimes a poor choice for a loop index. The compiler then cannot assume the loop will terminate, and generate worse code. Usually this doesn't matter -- until you discover it did.
Re:Bounded Integer: Header-only C++ library replaces integer...
by rleigh on Sunday September 29, 2019 @03:42PM
(#21109231)
Good point. Probably not a problem in practice for most containers, but yet another reason for why the STL (and C library, for that matter) should have used a signed size type from the beginning.
Re:Bounded Integer: Header-only C++ library replaces integer...
by nitwit005 on Sunday September 29, 2019 @06:10PM
(#21109928)
Yep, it's to match vector/array size_type and difference_type, although I tend to just use size_t and ptrdiff_t directly.
Re:Bounded Integer: Header-only C++ library replaces integer...
by glouwbug on Sunday September 29, 2019 @12:27PM
(#21107945)
It's a good choice. Sometimes your best choice for a general purpose int is
typedef Int int32_t;
for the entire compilation as a whole, and when things get screwy just bump Int up to int64_t and take the performance hit for the extra bit of safety