2
0
mirror of https://github.com/boostorg/random.git synced 2026-01-22 17:33:00 +00:00

fix various platform-specific compile problems

[SVN r16681]
This commit is contained in:
Jens Maurer
2002-12-22 21:27:42 +00:00
parent d954a4156d
commit b9fb804fa4
6 changed files with 51 additions and 36 deletions

View File

@@ -53,9 +53,6 @@ public:
// constant expressions. Avoid the check for now.
// BOOST_STATIC_ASSERT(m == 0 || a < m);
// BOOST_STATIC_ASSERT(m == 0 || c < m);
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
#endif
explicit linear_congruential(IntType x0 = 1)
: _modulus(modulus), _x(_modulus ? (x0 % _modulus) : x0)
@@ -64,6 +61,11 @@ public:
// overflow check
// disabled because it gives spurious "divide by zero" gcc warnings
// assert(m == 0 || (a*(m-1)+c) % m == (c < a ? c-a+m : c-a));
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
#endif
}
template<class It>

View File

@@ -52,13 +52,14 @@ public:
// BOOST_STATIC_ASSERT(0 < 2*q && 2*q < k);
// BOOST_STATIC_ASSERT(0 < s && s <= k-q);
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_integer);
BOOST_STATIC_ASSERT(!std::numeric_limits<UIntType>::is_signed);
#endif
explicit linear_feedback_shift(UIntType s0 = 341) : wordmask(0)
{
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_integer);
BOOST_STATIC_ASSERT(!std::numeric_limits<UIntType>::is_signed);
#endif
// avoid "left shift count >= with of type" warning
for(int i = 0; i < w; ++i)
wordmask |= (1u << i);
@@ -67,6 +68,12 @@ public:
template<class It> linear_feedback_shift(It& first, It last) : wordmask(0)
{
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<UIntType>::is_integer);
BOOST_STATIC_ASSERT(!std::numeric_limits<UIntType>::is_signed);
#endif
// avoid "left shift count >= with of type" warning
for(int i = 0; i < w; ++i)
wordmask |= (1u << i);

View File

@@ -50,12 +50,14 @@ public:
BOOST_STATIC_CONSTANT(unsigned int, long_lag = r);
BOOST_STATIC_CONSTANT(unsigned int, short_lag = s);
subtract_with_carry() {
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_signed);
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_signed);
BOOST_STATIC_ASSERT(std::numeric_limits<result_type>::is_integer);
#endif
subtract_with_carry() { seed(); }
seed();
}
explicit subtract_with_carry(uint32_t value) { seed(value); }
template<class Generator>
explicit subtract_with_carry(Generator & gen) { seed(gen); }

View File

@@ -205,7 +205,7 @@ class uniform_int
{
private:
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
typedef typename detail::uniform_int<std::numeric_limits<typename UniformRandomNumberGenerator::result_type>::is_integer>::impl<UniformRandomNumberGenerator, IntType>::type impl_type;
typedef typename detail::uniform_int<std::numeric_limits<typename UniformRandomNumberGenerator::result_type>::is_integer>::BOOST_NESTED_TEMPLATE impl<UniformRandomNumberGenerator, IntType>::type impl_type;
#else
BOOST_STATIC_CONSTANT(bool, base_float = (boost::is_float<typename UniformRandomNumberGenerator::result_type>::value == false));
typedef typename detail::uniform_int<base_float>::BOOST_NESTED_TEMPLATE impl<UniformRandomNumberGenerator, IntType>::type impl_type;
@@ -218,13 +218,14 @@ public:
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
#endif
explicit uniform_int(base_type & rng, IntType min = 0, IntType max = 9)
: impl(rng, min, max)
{ }
{
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
#endif
}
result_type min() const { return impl.min(); }
result_type max() const { return impl.max(); }

View File

@@ -107,14 +107,15 @@ public:
typedef UniformRandomNumberGenerator base_type;
typedef IntType result_type;
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
BOOST_STATIC_ASSERT(!std::numeric_limits<typename base_type::result_type>::is_integer);
#endif
uniform_smallint_float(base_type & rng, IntType min, IntType max)
: _rng(rng)
{
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
BOOST_STATIC_ASSERT(!std::numeric_limits<typename base_type::result_type>::is_integer);
#endif
assert(min < max);
}
@@ -176,7 +177,7 @@ class uniform_smallint
{
private:
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
typedef typename detail::uniform_smallint<std::numeric_limits<typename UniformRandomNumberGenerator::result_type>::is_integer>::impl<UniformRandomNumberGenerator, IntType>::type impl_type;
typedef typename detail::uniform_smallint<std::numeric_limits<typename UniformRandomNumberGenerator::result_type>::is_integer>::BOOST_NESTED_TEMPLATE impl<UniformRandomNumberGenerator, IntType>::type impl_type;
#else
BOOST_STATIC_CONSTANT(bool, base_float = (boost::is_float<typename UniformRandomNumberGenerator::result_type>::value == false));
typedef typename detail::uniform_smallint<base_float>::BOOST_NESTED_TEMPLATE impl<UniformRandomNumberGenerator, IntType>::type impl_type;
@@ -188,13 +189,14 @@ public:
typedef IntType result_type;
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
#endif
explicit uniform_smallint(base_type & rng, IntType min = 0, IntType max = 9)
: _impl(rng, min, max)
{ }
{
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<IntType>::is_integer);
#endif
}
result_type min() const { return _impl.min(); }
result_type max() const { return _impl.max(); }

View File

@@ -48,13 +48,8 @@ public:
BOOST_STATIC_CONSTANT(int, shift1 = s1);
BOOST_STATIC_CONSTANT(int, shfit2 = s2);
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::is_integer);
BOOST_STATIC_ASSERT(std::numeric_limits<typename base2_type::result_type>::is_integer);
BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::digits >= std::numeric_limits<typename base2_type::result_type>::digits);
#endif
xor_combine() : _rng1(), _rng2() { }
xor_combine() : _rng1(), _rng2()
{ }
xor_combine(const base1_type & rng1, const base2_type & rng2)
: _rng1(rng1), _rng2(rng2) { }
template<class It> xor_combine(It& first, It last)
@@ -71,6 +66,12 @@ public:
result_type operator()()
{
// MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::is_integer);
BOOST_STATIC_ASSERT(std::numeric_limits<typename base2_type::result_type>::is_integer);
BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::digits >= std::numeric_limits<typename base2_type::result_type>::digits);
#endif
return (_rng1() << s1) ^ (_rng2() << s2);
}