Boost logo

Boost :

From: Beman Dawes (beman_at_[hidden])
Date: 1999-08-03 20:34:14


At 12:27 AM 8/4/99 +0200, Jens Maurer wrote:

>Beman Dawes wrote:
>> * A template approach where the user would write code like:
>>
>> int_t<32>::exact // to obtain the 32-bit integer type
>> int_t<32>::max() // to obtain the maximum value
>
>We should probably use int_t<> only for getting the correct type
>and use numeric_limits<> for getting max/min values.

Yes, good point.

>The last line would read
>
> numeric_limits<int_t<32>::exact>::max()
>
>instead. If you need this more than once in application code,
>you are encouraged to employ a typedef to save typing.

Another good point!

If for 8, 16, 32, [and soon 64] bit types we include also typedefs,
then people who want/need shorter forms can use the typedefs, and
those who want/need generic code can use the int_exact<>,
int_least<>, etc, templates directly. The typedefs might only be
needed for the type; min and max don't appear as often.

    numeric_limits<int32>::max()

doesn't seem long enough to require a typedef.

>> While the template approach seems conceptually more elegant, I
find
>> the resulting user code unbearably ugly.
>
>As Dietmar already pointed out, there could be applications
>where specifying the width as a template parameter might be
>natural.

Maybe we can have both. A bit more complexity, but not a lot.

>Do we need the signed/unsigned distinction as a second "bool"
>template parameter in the above definitions?

No, it is a different type, like uint_least<32>::type, IMO.

--Beman


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