Ticket #2026: random.patch
File random.patch, 2.9 KB (added by , 14 years ago) |
---|
-
boost/random/uniform_int.hpp
25 25 #include <boost/detail/workaround.hpp> 26 26 #include <boost/random/uniform_smallint.hpp> 27 27 #include <boost/random/detail/signed_unsigned_tools.hpp> 28 #include <boost/type_traits/make_unsigned.hpp> 28 29 #ifdef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS 29 30 #include <boost/type_traits/is_float.hpp> 30 31 #endif … … 38 39 public: 39 40 typedef IntType input_type; 40 41 typedef IntType result_type; 41 typedef typename random::detail::make_unsigned<result_type>::type range_type;42 typedef typename make_unsigned<result_type>::type range_type; 42 43 43 44 explicit uniform_int(IntType min_arg = 0, IntType max_arg = 9) 44 45 : _min(min_arg), _max(max_arg) … … 61 62 { 62 63 typedef typename Engine::result_type base_result; 63 64 // ranges are always unsigned 64 typedef typename random::detail::make_unsigned<base_result>::type base_unsigned;65 typedef typename make_unsigned<base_result>::type base_unsigned; 65 66 const base_result bmin = (eng.min)(); 66 67 const base_unsigned brange = 67 68 random::detail::subtract<base_result>()((eng.max)(), (eng.min)()); -
boost/random/detail/signed_unsigned_tools.hpp
13 13 14 14 #include <boost/limits.hpp> 15 15 #include <boost/config.hpp> 16 #include <boost/type_traits/make_unsigned.hpp> 16 17 17 18 namespace boost { 18 19 namespace random { 19 20 namespace detail { 20 21 21 /*22 * Given an (integral) type T, returns the type "unsigned T".23 * (type_traits appears to be lacking the feature)24 */25 22 26 template<class T>27 struct make_unsigned { };28 29 template<>30 struct make_unsigned<char>31 {32 typedef unsigned char type;33 };34 35 template<>36 struct make_unsigned<signed char>37 {38 typedef unsigned char type;39 };40 41 template<>42 struct make_unsigned<unsigned char>43 {44 typedef unsigned char type;45 };46 47 template<>48 struct make_unsigned<short>49 {50 typedef unsigned short type;51 };52 53 template<>54 struct make_unsigned<unsigned short>55 {56 typedef unsigned short type;57 };58 59 template<>60 struct make_unsigned<int>61 {62 typedef unsigned int type;63 };64 65 template<>66 struct make_unsigned<unsigned int>67 {68 typedef unsigned int type;69 };70 71 template<>72 struct make_unsigned<long>73 {74 typedef unsigned long type;75 };76 77 template<>78 struct make_unsigned<unsigned long>79 {80 typedef unsigned long type;81 };82 83 #ifdef BOOST_HAS_LONG_LONG84 template<>85 struct make_unsigned<long long>86 {87 typedef unsigned long long type;88 };89 90 template<>91 struct make_unsigned<unsigned long long>92 {93 typedef unsigned long long type;94 };95 #endif96 97 98 23 /* 99 24 * Compute x - y, we know that x >= y, return an unsigned value. 100 25 */