fix doc example typo
[boost.git] / boost / random / variate_generator.hpp
blob1d22e49a8029ed23e6e0dd65eca043b37f936e52
1 /* boost random/variate_generator.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$
14 #ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP
15 #define BOOST_RANDOM_RANDOM_GENERATOR_HPP
17 #include <boost/config.hpp>
19 // implementation details
20 #include <boost/detail/workaround.hpp>
21 #include <boost/random/uniform_01.hpp>
22 #include <boost/random/detail/pass_through_engine.hpp>
23 #include <boost/random/detail/uniform_int_float.hpp>
24 #include <boost/random/detail/ptr_helper.hpp>
26 // Borland C++ 5.6.0 has problems using its numeric_limits traits as
27 // template parameters
28 #if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
29 #include <boost/type_traits/is_integral.hpp>
30 #endif
32 namespace boost {
34 namespace random {
35 namespace detail {
37 template<bool have_int, bool want_int>
38 struct engine_helper;
40 // for consistency, always have two levels of decorations
41 template<>
42 struct engine_helper<true, true>
44 template<class Engine, class DistInputType>
45 struct impl
47 typedef pass_through_engine<Engine> type;
51 template<>
52 struct engine_helper<false, false>
54 template<class Engine, class DistInputType>
55 struct impl
57 typedef uniform_01<Engine, DistInputType> type;
61 template<>
62 struct engine_helper<true, false>
64 template<class Engine, class DistInputType>
65 struct impl
67 typedef uniform_01<Engine, DistInputType> type;
71 template<>
72 struct engine_helper<false, true>
74 template<class Engine, class DistInputType>
75 struct impl
77 typedef uniform_int_float<Engine, unsigned long> type;
81 } // namespace detail
82 } // namespace random
85 template<class Engine, class Distribution>
86 class variate_generator
88 private:
89 typedef random::detail::pass_through_engine<Engine> decorated_engine;
91 public:
92 typedef typename decorated_engine::base_type engine_value_type;
93 typedef Engine engine_type;
94 typedef Distribution distribution_type;
95 typedef typename Distribution::result_type result_type;
97 variate_generator(Engine e, Distribution d)
98 : _eng(decorated_engine(e)), _dist(d) { }
100 result_type operator()() { return _dist(_eng); }
101 template<class T>
102 result_type operator()(T value) { return _dist(_eng, value); }
104 engine_value_type& engine() { return _eng.base().base(); }
105 const engine_value_type& engine() const { return _eng.base().base(); }
107 distribution_type& distribution() { return _dist; }
108 const distribution_type& distribution() const { return _dist; }
110 result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
111 result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
113 private:
114 #if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
115 typedef typename random::detail::engine_helper<
116 boost::is_integral<typename decorated_engine::result_type>::value,
117 boost::is_integral<typename Distribution::input_type>::value
118 >::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
119 #else
120 enum {
121 have_int = std::numeric_limits<typename decorated_engine::result_type>::is_integer,
122 want_int = std::numeric_limits<typename Distribution::input_type>::is_integer
124 typedef typename random::detail::engine_helper<have_int, want_int>::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
125 #endif
127 internal_engine_type _eng;
128 distribution_type _dist;
131 } // namespace boost
133 #endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP