Boost logo

Boost :

From: Gennaro Prota (gennaro_prota_at_[hidden])
Date: 2003-01-09 12:53:31


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

>I basically agree with everything you've said, especially about the
>separate traits (metafunctions)! I was just pointing out some overlap
>with existing libraries.

Ok, here's what I propose:

a) cleaning up the whole implementation of boost/detail/limits.hpp by

     - getting rid of all the stuff like:

          template<>
          class numeric_limits<bool>
            : public _Integer_limits<bool, false, true, 0>
          {};

          template<>
          class numeric_limits<char>
            : public _Integer_limits<char, CHAR_MIN, CHAR_MAX>
          {};

          template<>
          class numeric_limits<signed char>
            : public _Integer_limits<signed char, SCHAR_MIN,
          SCHAR_MAX>
          {};

      because, of course, max_of and min_of can be used for this.
      Example:

         static T min() throw() { return min_of<T>::value; }

          [Or, if you prefer... ;-)

             return implicit_cast<T> (min_of<T>::value);

          ]

   - in general, calculating values instead of providing them
     explicitly when this is feasible in a portable way.

     Example: for built-in integers, instead of having a hack like

         template <class _Int,
                   _Int __imin,
                   _Int __imax,
                   int __idigits = -1>
         class _Integer_limits : public _Numeric_limits_base<_Int>

     that either "calculates" (wrongly) digits or takes the opposite
     of the value that the user passes (__idigits), we could have:

         BOOST_STATIC_CONSTANT(int, digits, precision<T>::value);

    Note, as to digits and digits10, that a similar clean up is
    possible for floating point types too, by adding e.g.:

         template <typename T> struct digits {
            BOOST_STATIC_CONSTANT(int, value = 0); // dummy value;
                                                       (debatable)
        };

        template <> struct digits<float>
          { BOOST_STATIC_CONSTANT(int, value = FLT_MANT_DIG); };
        template <> struct digits<double>
          { BOOST_STATIC_CONSTANT(int, value = DBL_MANT_DIG); };
        template <> struct digits<long double>
          { BOOST_STATIC_CONSTANT(int, value = LDBL_MANT_DIG);};

b) Modifying integer_traits.hpp to use max_of and min_of. This is just
for backward compatibility because I think integer_traits should be
simply deprecated (if the information one wants to provide is
const_max and const_min for what reason should he add that information
somewhere else, like numeric_limits<>? And what is the derivation good
for?)

What do you think? If there aren't objections I could at least upload
the needed code to the boost sandbox.

Genny.


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