Boost logo

Boost :

From: Jens Maurer (Jens.Maurer_at_[hidden])
Date: 2002-01-03 15:25:51

Daryle Walker wrote:
> 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!

The documentation appears to be lacking, because it doesn't
specify the type of "value" at all. It would really help
to see the definition of the various classes instead of just
their declaration.

And, looking at the implementation, there is indeed no type
magic going on: boost/integer/static_min_max.hpp says the
value is just of type "long" or "unsigned long".

And now back to my point: Since this is a min/max template,
one of the arguments will be returned. And, usually, I know
the type/size of the arguments, so I can transmit it.
(This is all compile-time.)

template<class T, T value1, T value2>
struct static_min
   BOOST_STATIC_CONSTANT(T, value = /* as usual */);

// this usually required definition is currently lacking as well
template<class T, T value1, T value2>
const T static_min<T, value1, value2>::value;

I still believe this template is a natural expansion and
merge of the currently available static_signed_min and
static_unsigned_min templates.

Please argue specifically why the current state of affairs
in boost/integer/static_min_max.hpp is better than the
suggestion above.

(Similarly with static_max.)

> > * 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.

gcc does so.

Jens Maurer

Boost list run by bdawes at, gregod at, cpdaniel at, john at