1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/stdapis/boost/random/xor_combine.hpp Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -0,0 +1,130 @@
1.4 +/* boost random/xor_combine.hpp header file
1.5 + *
1.6 + * Copyright Jens Maurer 2002
1.7 + * Distributed under the Boost Software License, Version 1.0. (See
1.8 + * accompanying file LICENSE_1_0.txt or copy at
1.9 + * http://www.boost.org/LICENSE_1_0.txt)
1.10 + *
1.11 + * See http://www.boost.org for most recent version including documentation.
1.12 + *
1.13 + * $Id: xor_combine.hpp,v 1.13 2005/05/21 15:57:00 dgregor Exp $
1.14 + *
1.15 + */
1.16 +
1.17 +#ifndef BOOST_RANDOM_XOR_COMBINE_HPP
1.18 +#define BOOST_RANDOM_XOR_COMBINE_HPP
1.19 +
1.20 +#include <iostream>
1.21 +#include <cassert>
1.22 +#include <algorithm> // for std::min and std::max
1.23 +#include <boost/config.hpp>
1.24 +#include <boost/limits.hpp>
1.25 +#include <boost/static_assert.hpp>
1.26 +#include <boost/cstdint.hpp> // uint32_t
1.27 +
1.28 +
1.29 +namespace boost {
1.30 +namespace random {
1.31 +
1.32 +template<class URNG1, int s1, class URNG2, int s2,
1.33 +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
1.34 + typename URNG1::result_type
1.35 +#else
1.36 + uint32_t
1.37 +#endif
1.38 + val = 0>
1.39 +class xor_combine
1.40 +{
1.41 +public:
1.42 + typedef URNG1 base1_type;
1.43 + typedef URNG2 base2_type;
1.44 + typedef typename base1_type::result_type result_type;
1.45 +
1.46 + BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
1.47 + BOOST_STATIC_CONSTANT(int, shift1 = s1);
1.48 + BOOST_STATIC_CONSTANT(int, shfit2 = s2);
1.49 +
1.50 + xor_combine() : _rng1(), _rng2()
1.51 + { }
1.52 + xor_combine(const base1_type & rng1, const base2_type & rng2)
1.53 + : _rng1(rng1), _rng2(rng2) { }
1.54 + template<class It> xor_combine(It& first, It last)
1.55 + : _rng1(first, last), _rng2( /* advanced by other call */ first, last) { }
1.56 + void seed() { _rng1.seed(); _rng2.seed(); }
1.57 + template<class It> void seed(It& first, It last)
1.58 + {
1.59 + _rng1.seed(first, last);
1.60 + _rng2.seed(first, last);
1.61 + }
1.62 +
1.63 + const base1_type& base1() { return _rng1; }
1.64 + const base2_type& base2() { return _rng2; }
1.65 +
1.66 + result_type operator()()
1.67 + {
1.68 + // MSVC fails BOOST_STATIC_ASSERT with std::numeric_limits at class scope
1.69 +#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
1.70 + BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::is_integer);
1.71 + BOOST_STATIC_ASSERT(std::numeric_limits<typename base2_type::result_type>::is_integer);
1.72 + BOOST_STATIC_ASSERT(std::numeric_limits<typename base1_type::result_type>::digits >= std::numeric_limits<typename base2_type::result_type>::digits);
1.73 +#endif
1.74 + return (_rng1() << s1) ^ (_rng2() << s2);
1.75 + }
1.76 +
1.77 + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::min BOOST_PREVENT_MACRO_SUBSTITUTION((_rng1.min)(), (_rng2.min)()); }
1.78 + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return std::max BOOST_PREVENT_MACRO_SUBSTITUTION((_rng1.min)(), (_rng2.max)()); }
1.79 + static bool validation(result_type x) { return val == x; }
1.80 +
1.81 +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
1.82 +
1.83 +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
1.84 + template<class CharT, class Traits>
1.85 + friend std::basic_ostream<CharT,Traits>&
1.86 + operator<<(std::basic_ostream<CharT,Traits>& os, const xor_combine& s)
1.87 + {
1.88 + os << s._rng1 << " " << s._rng2 << " ";
1.89 + return os;
1.90 + }
1.91 +
1.92 + template<class CharT, class Traits>
1.93 + friend std::basic_istream<CharT,Traits>&
1.94 + operator>>(std::basic_istream<CharT,Traits>& is, xor_combine& s)
1.95 + {
1.96 + is >> s._rng1 >> std::ws >> s._rng2 >> std::ws;
1.97 + return is;
1.98 + }
1.99 +#endif
1.100 +
1.101 + friend bool operator==(const xor_combine& x, const xor_combine& y)
1.102 + { return x._rng1 == y._rng1 && x._rng2 == y._rng2; }
1.103 + friend bool operator!=(const xor_combine& x, const xor_combine& y)
1.104 + { return !(x == y); }
1.105 +#else
1.106 + // Use a member function; Streamable concept not supported.
1.107 + bool operator==(const xor_combine& rhs) const
1.108 + { return _rng1 == rhs._rng1 && _rng2 == rhs._rng2; }
1.109 + bool operator!=(const xor_combine& rhs) const
1.110 + { return !(*this == rhs); }
1.111 +#endif
1.112 +
1.113 +private:
1.114 + base1_type _rng1;
1.115 + base2_type _rng2;
1.116 +};
1.117 +
1.118 +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
1.119 +// A definition is required even for integral static constants
1.120 +template<class URNG1, int s1, class URNG2, int s2,
1.121 +#ifndef BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS
1.122 + typename URNG1::result_type
1.123 +#else
1.124 + uint32_t
1.125 +#endif
1.126 + val>
1.127 +const bool xor_combine<URNG1, s1, URNG2, s2, val>::has_fixed_range;
1.128 +#endif
1.129 +
1.130 +} // namespace random
1.131 +} // namespace boost
1.132 +
1.133 +#endif // BOOST_RANDOM_XOR_COMBINE_HPP