Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2002-01-03 00:20:30


on 1/1/02 6:12 PM, Jens Maurer at Jens.Maurer_at_[hidden] wrote:

> I'm only now reading the recent integer library additions from Daryle
> Walker, which are already integrated in the CVS.
>
> I've got these comments (I'm only reading the docs, so these
> issues may very well be problems with the documentation only):
>
> - static_log2 takes an "unsigned long" as its parameter,
> but its "value" is only an "int". This is, strictly speaking,
> non-portable code, since there might be machines where an
> unsigned long is so large that its logarithm doesn't fit into
> an int. I agree that this is *very* unlikely, but I'd like
> to see a note in the documentation.

To go beyond the range of an "int," the "unsigned long" type needs to
support values greater or equal to 2^MAXINT. As you said, this is very
unlikely. Furthermore, the "int" type is used in a lot of parameters of the
std::numeric_traits<> class templates, so the parameters of numeric types
have to be small enough to fit in an "int" already. This means that I'm
safe.

> - I don't like the extrema templates. I'd like to see
> the integral type as a template parameter, and not as a
> fixed "long/unsigned long" choice. Reasons:

Those templates return the appropriately-sized type for the given value
anyway. If you specify the integral type as a template parameter, then you
already know the range of numbers needed, and so don't need to use the
templates!

> * There are compilers where "long long" is actually an
> integral type. Currently, I am not able to use boost's
> compile-time min/max with values of that type.

I've heard that some compilers that support "long long" and "unsigned long
long" don't support them as types for value-based template parameters.
Since we don't have a config for that, I decided to play it safe and assume
that the double-long types aren't there. (They aren't official, after all.)

> * The "long / unsigned long" distinction would be merged
> into a single template (one for min, one for max) only,
> static_max<> and static_min<>. This seems more orthogonal.
>
> * Since these min/max "functions" are used for compile-time
> evaluations anyway, I don't buy the argument that "each
> additional template parameter halves the remaining number of
> users" in this case: The target audience is not someone having
> only a minor understanding of templates and trying to use a
> smart pointer, but someone actually doing template (meta-)
> programming.
>
>
> Daryle, what do you think?

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

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