1 /* boost random/discard_block.hpp header file
\r
3 * Copyright Jens Maurer 2002
\r
4 * Distributed under the Boost Software License, Version 1.0. (See
\r
5 * accompanying file LICENSE_1_0.txt or copy at
\r
6 * http://www.boost.org/LICENSE_1_0.txt)
\r
8 * See http://www.boost.org for most recent version including documentation.
\r
10 * $Id: discard_block.hpp 53871 2009-06-13 17:54:06Z steven_watanabe $
\r
13 * 2001-03-02 created
\r
16 #ifndef BOOST_RANDOM_DISCARD_BLOCK_HPP
\r
17 #define BOOST_RANDOM_DISCARD_BLOCK_HPP
\r
20 #include <boost/config.hpp>
\r
21 #include <boost/limits.hpp>
\r
22 #include <boost/static_assert.hpp>
\r
23 #include <boost/random/detail/config.hpp>
\r
29 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
\r
33 typedef UniformRandomNumberGenerator base_type;
\r
34 typedef typename base_type::result_type result_type;
\r
36 BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
\r
37 BOOST_STATIC_CONSTANT(unsigned int, total_block = p);
\r
38 BOOST_STATIC_CONSTANT(unsigned int, returned_block = r);
\r
40 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
\r
41 BOOST_STATIC_ASSERT(total_block >= returned_block);
\r
44 discard_block() : _rng(), _n(0) { }
\r
45 explicit discard_block(const base_type & rng) : _rng(rng), _n(0) { }
\r
46 template<class T> explicit discard_block(T s) : _rng(s), _n(0) {}
\r
47 template<class It> discard_block(It& first, It last)
\r
48 : _rng(first, last), _n(0) { }
\r
49 void seed() { _rng.seed(); _n = 0; }
\r
50 template<class T> void seed(T s) { _rng.seed(s); _n = 0; }
\r
51 template<class It> void seed(It& first, It last)
\r
52 { _n = 0; _rng.seed(first, last); }
\r
54 const base_type& base() const { return _rng; }
\r
56 result_type operator()()
\r
58 if(_n >= returned_block) {
\r
59 // discard values of random number generator
\r
60 for( ; _n < total_block; ++_n)
\r
68 result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); }
\r
69 result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); }
\r
70 static bool validation(result_type x) { return true; } // dummy
\r
72 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
\r
74 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
\r
75 template<class CharT, class Traits>
\r
76 friend std::basic_ostream<CharT,Traits>&
\r
77 operator<<(std::basic_ostream<CharT,Traits>& os, const discard_block& s)
\r
79 os << s._rng << " " << s._n << " ";
\r
83 template<class CharT, class Traits>
\r
84 friend std::basic_istream<CharT,Traits>&
\r
85 operator>>(std::basic_istream<CharT,Traits>& is, discard_block& s)
\r
87 is >> s._rng >> std::ws >> s._n >> std::ws;
\r
92 friend bool operator==(const discard_block& x, const discard_block& y)
\r
93 { return x._rng == y._rng && x._n == y._n; }
\r
94 friend bool operator!=(const discard_block& x, const discard_block& y)
\r
95 { return !(x == y); }
\r
97 // Use a member function; Streamable concept not supported.
\r
98 bool operator==(const discard_block& rhs) const
\r
99 { return _rng == rhs._rng && _n == rhs._n; }
\r
100 bool operator!=(const discard_block& rhs) const
\r
101 { return !(*this == rhs); }
\r
109 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
\r
110 // A definition is required even for integral static constants
\r
111 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
\r
112 const bool discard_block<UniformRandomNumberGenerator, p, r>::has_fixed_range;
\r
113 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
\r
114 const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::total_block;
\r
115 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
\r
116 const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::returned_block;
\r
119 } // namespace random
\r
121 } // namespace boost
\r
123 #endif // BOOST_RANDOM_DISCARD_BLOCK_HPP
\r