1
/* boost random/discard_block.hpp header file
3
* Copyright Jens Maurer 2002
4
* Permission to use, copy, modify, sell, and distribute this software
5
* is hereby granted without fee provided that the above copyright notice
6
* appears in all copies and that both that copyright notice and this
7
* permission notice appear in supporting documentation,
9
* Jens Maurer makes no representations about the suitability of this
10
* software for any purpose. It is provided "as is" without express or
13
* See http://www.boost.org for most recent version including documentation.
15
* $Id: discard_block.hpp,v 1.1 2004/02/27 03:16:46 pseudonym Exp $
21
#ifndef BOOST_RANDOM_DISCARD_BLOCK_HPP
22
#define BOOST_RANDOM_DISCARD_BLOCK_HPP
25
#include <boost/config.hpp>
26
#include <boost/limits.hpp>
27
#include <boost/static_assert.hpp>
33
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
37
typedef UniformRandomNumberGenerator base_type;
38
typedef typename base_type::result_type result_type;
40
BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
41
BOOST_STATIC_CONSTANT(unsigned int, total_block = p);
42
BOOST_STATIC_CONSTANT(unsigned int, returned_block = r);
44
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
45
BOOST_STATIC_ASSERT(total_block >= returned_block);
48
discard_block() : _rng(), _n(0) { }
49
explicit discard_block(const base_type & rng) : _rng(rng), _n(0) { }
50
template<class It> discard_block(It& first, It last)
51
: _rng(first, last), _n(0) { }
52
template<class T> void seed(T s) { _rng.seed(s); _n = 0; }
53
template<class It> void seed(It& first, It last)
54
{ _n = 0; _rng.seed(first, last); }
56
const base_type& base() const { return _rng; }
58
result_type operator()()
60
if(_n >= returned_block) {
61
// discard values of random number generator
62
for( ; _n < total_block; ++_n)
70
result_type min() const { return _rng.min(); }
71
result_type max() const { return _rng.max(); }
72
static bool validation(result_type x) { return true; } // dummy
74
#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
76
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
77
template<class CharT, class Traits>
78
friend std::basic_ostream<CharT,Traits>&
79
operator<<(std::basic_ostream<CharT,Traits>& os, const discard_block& s)
81
os << s._rng << " " << s._n << " ";
85
template<class CharT, class Traits>
86
friend std::basic_istream<CharT,Traits>&
87
operator>>(std::basic_istream<CharT,Traits>& is, discard_block& s)
89
is >> s._rng >> std::ws >> s._n >> std::ws;
94
friend bool operator==(const discard_block& x, const discard_block& y)
95
{ return x._rng == y._rng && x._n == y._n; }
96
friend bool operator!=(const discard_block& x, const discard_block& y)
99
// Use a member function; Streamable concept not supported.
100
bool operator==(const discard_block& rhs) const
101
{ return _rng == rhs._rng && _n == rhs._n; }
102
bool operator!=(const discard_block& rhs) const
103
{ return !(*this == rhs); }
111
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
112
// A definition is required even for integral static constants
113
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
114
const bool discard_block<UniformRandomNumberGenerator, p, r>::has_fixed_range;
115
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
116
const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::total_block;
117
template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
118
const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::returned_block;
121
} // namespace random
125
#endif // BOOST_RANDOM_DISCARD_BLOCK_HPP