Boost logo

Boost :

Subject: Re: [boost] [safe_numerics] questioning the basic idea
From: Lee Clagett (forum_at_[hidden])
Date: 2014-11-18 21:34:04


On Tue, Nov 18, 2014 at 7:57 PM, David Stone <david_at_[hidden]> wrote:

> This is an issue that is especially important to me, as I have written a
> library that also has the goal of making integer arithmetic safe: the
> bounded::integer library: http://doublewise.net/c++/bounded/ . I presented
> this library at C++Now 2014 this year. It has a different philosophy from
> the checked integer type that you described. It instead has compile-time
> min and max bounds on each integer type, and the goal is to replace all
> uses of built-in integer types. The result of the arithmetic operators is a
> new type that is able to hold any result of the operation (so
> bounded::integer<1, 10> + bounded::integer<4, 7> == bounded::integer<5,
> 17>).
>
>
Your implementation appears to also disable implicit conversions if the
destination type is smaller. I abhore the C++ implicit conversion of
integers, and I started to write an implementation that did only this
(obviously I did not know about either of these libraries). Does anyone
else find a library that only does a compile-time implicit conversion check
useful? I know gcc and clang both have warnings that would do just this,
but I also like the idea of having it consistent across any compiler. Might
add too much overhead in compilation time for such a small feature.

Also, what if one (or both) of these libraries added named ("add",
"subtract", etc.) NOEXCEPT functions that returned bool? Overflow could be
checked and handled without a try catch block.

Lee


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk