fix doc example typo
[boost.git] / boost / random / discard_block.hpp
blobda3f9b13440f9b85f75b0bf3792efd8919d7ef0a
1 /* boost random/discard_block.hpp header file
3 * Copyright Jens Maurer 2002
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
8 * See http://www.boost.org for most recent version including documentation.
10 * $Id$
12 * Revision history
13 * 2001-03-02 created
16 #ifndef BOOST_RANDOM_DISCARD_BLOCK_HPP
17 #define BOOST_RANDOM_DISCARD_BLOCK_HPP
19 #include <iostream>
20 #include <boost/config.hpp>
21 #include <boost/limits.hpp>
22 #include <boost/static_assert.hpp>
23 #include <boost/random/detail/config.hpp>
26 namespace boost {
27 namespace random {
29 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
30 class discard_block
32 public:
33 typedef UniformRandomNumberGenerator base_type;
34 typedef typename base_type::result_type result_type;
36 BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
37 BOOST_STATIC_CONSTANT(unsigned int, total_block = p);
38 BOOST_STATIC_CONSTANT(unsigned int, returned_block = r);
40 #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
41 BOOST_STATIC_ASSERT(total_block >= returned_block);
42 #endif
44 discard_block() : _rng(), _n(0) { }
45 explicit discard_block(const base_type & rng) : _rng(rng), _n(0) { }
46 template<class It> discard_block(It& first, It last)
47 : _rng(first, last), _n(0) { }
48 void seed() { _rng.seed(); _n = 0; }
49 template<class T> void seed(T s) { _rng.seed(s); _n = 0; }
50 template<class It> void seed(It& first, It last)
51 { _n = 0; _rng.seed(first, last); }
53 const base_type& base() const { return _rng; }
55 result_type operator()()
57 if(_n >= returned_block) {
58 // discard values of random number generator
59 for( ; _n < total_block; ++_n)
60 _rng();
61 _n = 0;
63 ++_n;
64 return _rng();
67 result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); }
68 result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); }
69 static bool validation(result_type x) { return true; } // dummy
71 #ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
73 #ifndef BOOST_RANDOM_NO_STREAM_OPERATORS
74 template<class CharT, class Traits>
75 friend std::basic_ostream<CharT,Traits>&
76 operator<<(std::basic_ostream<CharT,Traits>& os, const discard_block& s)
78 os << s._rng << " " << s._n << " ";
79 return os;
82 template<class CharT, class Traits>
83 friend std::basic_istream<CharT,Traits>&
84 operator>>(std::basic_istream<CharT,Traits>& is, discard_block& s)
86 is >> s._rng >> std::ws >> s._n >> std::ws;
87 return is;
89 #endif
91 friend bool operator==(const discard_block& x, const discard_block& y)
92 { return x._rng == y._rng && x._n == y._n; }
93 friend bool operator!=(const discard_block& x, const discard_block& y)
94 { return !(x == y); }
95 #else
96 // Use a member function; Streamable concept not supported.
97 bool operator==(const discard_block& rhs) const
98 { return _rng == rhs._rng && _n == rhs._n; }
99 bool operator!=(const discard_block& rhs) const
100 { return !(*this == rhs); }
101 #endif
103 private:
104 base_type _rng;
105 unsigned int _n;
108 #ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
109 // A definition is required even for integral static constants
110 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
111 const bool discard_block<UniformRandomNumberGenerator, p, r>::has_fixed_range;
112 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
113 const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::total_block;
114 template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
115 const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::returned_block;
116 #endif
118 } // namespace random
120 } // namespace boost
122 #endif // BOOST_RANDOM_DISCARD_BLOCK_HPP