annotate DEPENDENCIES/generic/include/boost/random/variate_generator.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 /* boost random/variate_generator.hpp header file
Chris@16 2 *
Chris@16 3 * Copyright Jens Maurer 2002
Chris@16 4 * Copyright Steven Watanabe 2011
Chris@16 5 * Distributed under the Boost Software License, Version 1.0. (See
Chris@16 6 * accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 * http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8 *
Chris@16 9 * See http://www.boost.org for most recent version including documentation.
Chris@16 10 *
Chris@101 11 * $Id$
Chris@16 12 *
Chris@16 13 */
Chris@16 14
Chris@16 15 #ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP
Chris@16 16 #define BOOST_RANDOM_RANDOM_GENERATOR_HPP
Chris@16 17
Chris@16 18 #include <boost/random/detail/ptr_helper.hpp>
Chris@16 19
Chris@16 20 #include <boost/random/detail/disable_warnings.hpp>
Chris@16 21
Chris@16 22 namespace boost {
Chris@16 23
Chris@16 24 /// \cond hide_private_members
Chris@16 25
Chris@16 26 namespace random {
Chris@16 27
Chris@16 28 ///\endcond
Chris@16 29
Chris@16 30 /**
Chris@16 31 * A random variate generator is used to join a random number
Chris@16 32 * generator together with a random number distribution.
Chris@16 33 * Boost.Random provides a vast choice of \generators as well
Chris@16 34 * as \distributions.
Chris@16 35 *
Chris@16 36 * The argument for the template parameter Engine shall be of
Chris@16 37 * the form U, U&, or U*, where U models a
Chris@16 38 * \uniform_random_number_generator. Then, the member
Chris@16 39 * engine_value_type names U (not the pointer or reference to U).
Chris@16 40 *
Chris@16 41 * Specializations of @c variate_generator satisfy the
Chris@16 42 * requirements of CopyConstructible. They also satisfy the
Chris@16 43 * requirements of Assignable unless the template parameter
Chris@16 44 * Engine is of the form U&.
Chris@16 45 *
Chris@16 46 * The complexity of all functions specified in this section
Chris@16 47 * is constant. No function described in this section except
Chris@16 48 * the constructor throws an exception.
Chris@16 49 */
Chris@16 50 template<class Engine, class Distribution>
Chris@16 51 class variate_generator
Chris@16 52 {
Chris@16 53 private:
Chris@16 54 typedef boost::random::detail::ptr_helper<Engine> helper_type;
Chris@16 55 public:
Chris@16 56 typedef typename helper_type::value_type engine_value_type;
Chris@16 57 typedef Engine engine_type;
Chris@16 58 typedef Distribution distribution_type;
Chris@16 59 typedef typename Distribution::result_type result_type;
Chris@16 60
Chris@16 61 /**
Chris@16 62 * Constructs a @c variate_generator object with the associated
Chris@16 63 * \uniform_random_number_generator eng and the associated
Chris@16 64 * \random_distribution d.
Chris@16 65 *
Chris@16 66 * Throws: If and what the copy constructor of Engine or
Chris@16 67 * Distribution throws.
Chris@16 68 */
Chris@16 69 variate_generator(Engine e, Distribution d)
Chris@16 70 : _eng(e), _dist(d) { }
Chris@16 71
Chris@16 72 /** Returns: distribution()(engine()) */
Chris@16 73 result_type operator()() { return _dist(engine()); }
Chris@16 74 /**
Chris@16 75 * Returns: distribution()(engine(), value).
Chris@16 76 */
Chris@16 77 template<class T>
Chris@16 78 result_type operator()(const T& value) { return _dist(engine(), value); }
Chris@16 79
Chris@16 80 /**
Chris@16 81 * Returns: A reference to the associated uniform random number generator.
Chris@16 82 */
Chris@16 83 engine_value_type& engine() { return helper_type::ref(_eng); }
Chris@16 84 /**
Chris@16 85 * Returns: A reference to the associated uniform random number generator.
Chris@16 86 */
Chris@16 87 const engine_value_type& engine() const { return helper_type::ref(_eng); }
Chris@16 88
Chris@16 89 /** Returns: A reference to the associated \random_distribution. */
Chris@16 90 distribution_type& distribution() { return _dist; }
Chris@16 91 /**
Chris@16 92 * Returns: A reference to the associated random distribution.
Chris@16 93 */
Chris@16 94 const distribution_type& distribution() const { return _dist; }
Chris@16 95
Chris@16 96 /**
Chris@16 97 * Precondition: distribution().min() is well-formed
Chris@16 98 *
Chris@16 99 * Returns: distribution().min()
Chris@16 100 */
Chris@16 101 result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
Chris@16 102 /**
Chris@16 103 * Precondition: distribution().max() is well-formed
Chris@16 104 *
Chris@16 105 * Returns: distribution().max()
Chris@16 106 */
Chris@16 107 result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
Chris@16 108
Chris@16 109 private:
Chris@16 110 Engine _eng;
Chris@16 111 distribution_type _dist;
Chris@16 112 };
Chris@16 113
Chris@16 114 } // namespace random
Chris@16 115
Chris@16 116 using random::variate_generator;
Chris@16 117
Chris@16 118 } // namespace boost
Chris@16 119
Chris@16 120 #include <boost/random/detail/enable_warnings.hpp>
Chris@16 121
Chris@16 122 #endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP