epoc32/include/stdapis/boost/detail/numeric_traits.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/detail/numeric_traits.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,191 @@
     1.4 +// (C) Copyright David Abrahams 2001, Howard Hinnant 2001.
     1.5 +//
     1.6 +// Distributed under the Boost Software License, Version 1.0. (See
     1.7 +// accompanying file LICENSE_1_0.txt or copy at
     1.8 +// http://www.boost.org/LICENSE_1_0.txt)
     1.9 +//
    1.10 +// Template class numeric_traits<Number> --
    1.11 +//
    1.12 +//    Supplies:
    1.13 +//
    1.14 +//      typedef difference_type -- a type used to represent the difference
    1.15 +//      between any two values of Number.
    1.16 +//
    1.17 +//    Support:
    1.18 +//      1. Not all specializations are supplied
    1.19 +//
    1.20 +//      2. Use of specializations that are not supplied will cause a
    1.21 +//      compile-time error
    1.22 +//
    1.23 +//      3. Users are free to specialize numeric_traits for any type.
    1.24 +//
    1.25 +//      4. Right now, specializations are only supplied for integer types.
    1.26 +//
    1.27 +//      5. On implementations which do not supply compile-time constants in
    1.28 +//      std::numeric_limits<>, only specializations for built-in integer types
    1.29 +//      are supplied.
    1.30 +//
    1.31 +//      6. Handling of numbers whose range of representation is at least as
    1.32 +//      great as boost::intmax_t can cause some differences to be
    1.33 +//      unrepresentable in difference_type:
    1.34 +//
    1.35 +//        Number    difference_type
    1.36 +//        ------    ---------------
    1.37 +//        signed    Number
    1.38 +//        unsigned  intmax_t
    1.39 +//
    1.40 +// template <class Number> typename numeric_traits<Number>::difference_type
    1.41 +// numeric_distance(Number x, Number y)
    1.42 +//    computes (y - x), attempting to avoid overflows.
    1.43 +//
    1.44 +
    1.45 +// See http://www.boost.org for most recent version including documentation.
    1.46 +
    1.47 +// Revision History
    1.48 +// 11 Feb 2001 - Use BOOST_STATIC_CONSTANT (David Abrahams)
    1.49 +// 11 Feb 2001 - Rolled back ineffective Borland-specific code
    1.50 +//               (David Abrahams)
    1.51 +// 10 Feb 2001 - Rolled in supposed Borland fixes from John Maddock, but
    1.52 +//               not seeing any improvement yet (David Abrahams)
    1.53 +// 06 Feb 2001 - Factored if_true out into boost/detail/select_type.hpp
    1.54 +//               (David Abrahams)
    1.55 +// 23 Jan 2001 - Fixed logic of difference_type selection, which was
    1.56 +//               completely wack. In the process, added digit_traits<>
    1.57 +//               to compute the number of digits in intmax_t even when
    1.58 +//               not supplied by numeric_limits<>. (David Abrahams)
    1.59 +// 21 Jan 2001 - Created (David Abrahams)
    1.60 +
    1.61 +#ifndef BOOST_NUMERIC_TRAITS_HPP_DWA20001901
    1.62 +# define BOOST_NUMERIC_TRAITS_HPP_DWA20001901
    1.63 +
    1.64 +# include <boost/config.hpp>
    1.65 +# include <boost/cstdint.hpp>
    1.66 +# include <boost/static_assert.hpp>
    1.67 +# include <boost/type_traits.hpp>
    1.68 +# include <boost/detail/select_type.hpp>
    1.69 +# include <boost/limits.hpp>
    1.70 +
    1.71 +namespace boost { namespace detail {
    1.72 +
    1.73 +  // Template class is_signed -- determine whether a numeric type is signed
    1.74 +  // Requires that T is constructable from the literals -1 and 0.  Compile-time
    1.75 +  // error results if that requirement is not met (and thus signedness is not
    1.76 +  // likely to have meaning for that type).
    1.77 +  template <class Number>
    1.78 +  struct is_signed
    1.79 +  {
    1.80 +#if defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) || defined(BOOST_MSVC) && BOOST_MSVC <= 1300
    1.81 +    BOOST_STATIC_CONSTANT(bool, value = (Number(-1) < Number(0)));
    1.82 +#else
    1.83 +    BOOST_STATIC_CONSTANT(bool, value = std::numeric_limits<Number>::is_signed);
    1.84 +#endif
    1.85 +  };
    1.86 +
    1.87 +# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
    1.88 +  // digit_traits - compute the number of digits in a built-in integer
    1.89 +  // type. Needed for implementations on which numeric_limits is not specialized
    1.90 +  // for intmax_t (e.g. VC6).
    1.91 +  template <bool is_specialized> struct digit_traits_select;
    1.92 +
    1.93 +  // numeric_limits is specialized; just select that version of digits
    1.94 +  template <> struct digit_traits_select<true>
    1.95 +  {
    1.96 +      template <class T> struct traits
    1.97 +      {
    1.98 +          BOOST_STATIC_CONSTANT(int, digits = std::numeric_limits<T>::digits);
    1.99 +      };
   1.100 +  };
   1.101 +
   1.102 +  // numeric_limits is not specialized; compute digits from sizeof(T)
   1.103 +  template <> struct digit_traits_select<false>
   1.104 +  {
   1.105 +      template <class T> struct traits
   1.106 +      {
   1.107 +          BOOST_STATIC_CONSTANT(int, digits = (
   1.108 +              sizeof(T) * std::numeric_limits<unsigned char>::digits
   1.109 +              - (is_signed<T>::value ? 1 : 0))
   1.110 +              );
   1.111 +      };
   1.112 +  };
   1.113 +
   1.114 +  // here's the "usable" template
   1.115 +  template <class T> struct digit_traits
   1.116 +  {
   1.117 +      typedef digit_traits_select<
   1.118 +                ::std::numeric_limits<T>::is_specialized> selector;
   1.119 +      typedef typename selector::template traits<T> traits;
   1.120 +      BOOST_STATIC_CONSTANT(int, digits = traits::digits);
   1.121 +  };
   1.122 +#endif
   1.123 +
   1.124 +  // Template class integer_traits<Integer> -- traits of various integer types
   1.125 +  // This should probably be rolled into boost::integer_traits one day, but I
   1.126 +  // need it to work without <limits>
   1.127 +  template <class Integer>
   1.128 +  struct integer_traits
   1.129 +  {
   1.130 +# ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
   1.131 +   private:
   1.132 +      typedef Integer integer_type;
   1.133 +      typedef std::numeric_limits<integer_type> x;
   1.134 +#   if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
   1.135 +      // for some reason, MSVC asserts when it shouldn't unless we make these
   1.136 +      // local definitions
   1.137 +      BOOST_STATIC_CONSTANT(bool, is_integer = x::is_integer);
   1.138 +      BOOST_STATIC_CONSTANT(bool, is_specialized = x::is_specialized);
   1.139 +      
   1.140 +      BOOST_STATIC_ASSERT(is_integer);
   1.141 +      BOOST_STATIC_ASSERT(is_specialized);
   1.142 +#   endif
   1.143 +   public:
   1.144 +      typedef typename
   1.145 +      if_true<(int(x::is_signed)
   1.146 +              && (!int(x::is_bounded)
   1.147 +                 // digits is the number of no-sign bits
   1.148 +                  || (int(x::digits) + 1 >= digit_traits<boost::intmax_t>::digits)))>::template then<
   1.149 +        Integer,
   1.150 +          
   1.151 +      typename if_true<(int(x::digits) + 1 < digit_traits<signed int>::digits)>::template then<
   1.152 +        signed int,
   1.153 +
   1.154 +      typename if_true<(int(x::digits) + 1 < digit_traits<signed long>::digits)>::template then<
   1.155 +        signed long,
   1.156 +
   1.157 +   // else
   1.158 +        intmax_t
   1.159 +      >::type>::type>::type difference_type;
   1.160 +#else
   1.161 +      BOOST_STATIC_ASSERT(boost::is_integral<Integer>::value);
   1.162 +
   1.163 +      typedef typename
   1.164 +      if_true<(sizeof(Integer) >= sizeof(intmax_t))>::template then<
   1.165 +               
   1.166 +        typename if_true<(is_signed<Integer>::value)>::template then<
   1.167 +          Integer,
   1.168 +          intmax_t
   1.169 +        >::type,
   1.170 +
   1.171 +        typename if_true<(sizeof(Integer) < sizeof(std::ptrdiff_t))>::template then<
   1.172 +          std::ptrdiff_t,
   1.173 +          intmax_t
   1.174 +        >::type
   1.175 +      >::type difference_type;
   1.176 +# endif
   1.177 +  };
   1.178 +
   1.179 +  // Right now, only supports integers, but should be expanded.
   1.180 +  template <class Number>
   1.181 +  struct numeric_traits
   1.182 +  {
   1.183 +      typedef typename integer_traits<Number>::difference_type difference_type;
   1.184 +  };
   1.185 +
   1.186 +  template <class Number>
   1.187 +  typename numeric_traits<Number>::difference_type numeric_distance(Number x, Number y)
   1.188 +  {
   1.189 +      typedef typename numeric_traits<Number>::difference_type difference_type;
   1.190 +      return difference_type(y) - difference_type(x);
   1.191 +  }
   1.192 +}}
   1.193 +
   1.194 +#endif // BOOST_NUMERIC_TRAITS_HPP_DWA20001901