1 /* boost random/variate_generator.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: variate_generator.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $
\r
14 #ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP
\r
15 #define BOOST_RANDOM_RANDOM_GENERATOR_HPP
\r
17 #include <boost/config.hpp>
\r
19 // implementation details
\r
20 #include <boost/detail/workaround.hpp>
\r
21 #include <boost/random/uniform_01.hpp>
\r
22 #include <boost/random/detail/pass_through_engine.hpp>
\r
23 #include <boost/random/detail/uniform_int_float.hpp>
\r
24 #include <boost/random/detail/ptr_helper.hpp>
\r
26 // Borland C++ 5.6.0 has problems using its numeric_limits traits as
\r
27 // template parameters
\r
28 #if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
\r
29 #include <boost/type_traits/is_integral.hpp>
\r
32 #include <boost/random/detail/disable_warnings.hpp>
\r
39 template<bool have_int, bool want_int>
\r
40 struct engine_helper;
\r
42 // for consistency, always have two levels of decorations
\r
44 struct engine_helper<true, true>
\r
46 template<class Engine, class DistInputType>
\r
49 typedef pass_through_engine<Engine> type;
\r
54 struct engine_helper<false, false>
\r
56 template<class Engine, class DistInputType>
\r
59 typedef uniform_01<Engine, DistInputType> type;
\r
64 struct engine_helper<true, false>
\r
66 template<class Engine, class DistInputType>
\r
69 typedef uniform_01<Engine, DistInputType> type;
\r
74 struct engine_helper<false, true>
\r
76 template<class Engine, class DistInputType>
\r
79 typedef uniform_int_float<Engine, unsigned long> type;
\r
83 } // namespace detail
\r
84 } // namespace random
\r
87 template<class Engine, class Distribution>
\r
88 class variate_generator
\r
91 typedef random::detail::pass_through_engine<Engine> decorated_engine;
\r
94 typedef typename decorated_engine::base_type engine_value_type;
\r
95 typedef Engine engine_type;
\r
96 typedef Distribution distribution_type;
\r
97 typedef typename Distribution::result_type result_type;
\r
99 variate_generator(Engine e, Distribution d)
\r
100 : _eng(decorated_engine(e)), _dist(d) { }
\r
102 result_type operator()() { return _dist(_eng); }
\r
104 result_type operator()(T value) { return _dist(_eng, value); }
\r
106 engine_value_type& engine() { return _eng.base().base(); }
\r
107 const engine_value_type& engine() const { return _eng.base().base(); }
\r
109 distribution_type& distribution() { return _dist; }
\r
110 const distribution_type& distribution() const { return _dist; }
\r
112 result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
\r
113 result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
\r
116 #if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
\r
117 typedef typename random::detail::engine_helper<
\r
118 boost::is_integral<typename decorated_engine::result_type>::value,
\r
119 boost::is_integral<typename Distribution::input_type>::value
\r
120 >::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
\r
123 have_int = std::numeric_limits<typename decorated_engine::result_type>::is_integer,
\r
124 want_int = std::numeric_limits<typename Distribution::input_type>::is_integer
\r
126 typedef typename random::detail::engine_helper<have_int, want_int>::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
\r
129 internal_engine_type _eng;
\r
130 distribution_type _dist;
\r
133 } // namespace boost
\r
135 #include <boost/random/detail/disable_warnings.hpp>
\r
137 #endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP
\r