Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-08 11:31:02


On Wed, 08 Jan 2003 01:40:45 -0500, David Abrahams
<dave_at_[hidden]> wrote:

>Gennaro Prota <gennaro_prota_at_[hidden]> writes:
>
>> Hi everybody,
>>
>> the attached files contain a bunch of trivial stuff related to
>> integral types that I need in a lot of situations. Any interest for
>> inclusion into boost? Here's a summary:
>>
>
>Didn't Daryle Walker already implement some of these in the
>Boost.Integer library?

Ah. I wasn't aware of it, thanks (boost is quite large and knowing
everything is pretty much impossible, though the Integer library
should be one of the basics). As far as I've seen the only thing that
is implemented there too are the constant min and max. The
implementation uses numeric_limits though and that's already a bad
thing IMHO (coupling for no reason). I have to say that, e.g., width
and precision could be obtained without writing any special facility
through numeric_limits<>::digits if that template was portable, but it
isn't and our detail/limits.hpp isn't a good replacement, because for
instance it completely ignores possible padding bits (so it's only
waiting that we port boost somewhere where... ;-)) Incidentally, I had
never examined boost/detail/limits.hpp, I took it a look because I
wanted to replace our

   enum { bits_per_block = CHAR_BIT * sizeof(Block) };

with

   enum { bits_per_block = std::numeric_limits<Block>::digits };

It's obvious that when I saw how it "computes" digits I gave up :-)
Still the second line would be an improvement where a standard
<limits> is available. But I guess I could replace it with

   enum { bits_per_block = some_namespace::precision<Block>::value };

which is completely portable. That was just to show you a possible
use, of course, but as I said I need it all the times. Frankly, it
seems to me that those little templates are much cleaner and
understandable of the alternatives (also, let me say that if I were to
create something from scratch for standard C++ I would go for separate
traits, instead of an all-in-one solution like numeric_limits). But
it's also obvious that mine was just a proposal, and I don't expect
everyone to agree with me :-)

Genny.


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