X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=boost%2Frandom%2Fvariate_generator.hpp;fp=boost%2Frandom%2Fvariate_generator.hpp;h=ac698006c2638343146b386781e6bda3957d957b;hp=930d96187f987fb883e1e252f4fefc4f8b577213;hb=2d71eb92104693ca9baa5a2e1c23eeca776d8fd3;hpb=da57529b92adbb7ae74a89861cb39fb35ac7c62d diff --git a/boost/random/variate_generator.hpp b/boost/random/variate_generator.hpp index 930d961..ac69800 100644 --- a/boost/random/variate_generator.hpp +++ b/boost/random/variate_generator.hpp @@ -1,34 +1,22 @@ /* boost random/variate_generator.hpp header file * * Copyright Jens Maurer 2002 + * Copyright Steven Watanabe 2011 * Distributed under the Boost Software License, Version 1.0. (See * accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) * * See http://www.boost.org for most recent version including documentation. * - * $Id: variate_generator.hpp 60755 2010-03-22 00:45:06Z steven_watanabe $ + * $Id: variate_generator.hpp 71018 2011-04-05 21:27:52Z steven_watanabe $ * */ #ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP #define BOOST_RANDOM_RANDOM_GENERATOR_HPP -#include - -// implementation details -#include -#include -#include -#include #include -// Borland C++ 5.6.0 has problems using its numeric_limits traits as -// template parameters -#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564) -#include -#endif - #include namespace boost { @@ -36,54 +24,6 @@ namespace boost { /// \cond hide_private_members namespace random { -namespace detail { - -template -struct engine_helper; - -// for consistency, always have two levels of decorations -template<> -struct engine_helper -{ - template - struct impl - { - typedef pass_through_engine type; - }; -}; - -template<> -struct engine_helper -{ - template - struct impl - { - typedef uniform_01 type; - }; -}; - -template<> -struct engine_helper -{ - template - struct impl - { - typedef uniform_01 type; - }; -}; - -template<> -struct engine_helper -{ - template - struct impl - { - typedef uniform_int_float type; - }; -}; - -} // namespace detail -} // namespace random ///\endcond @@ -93,9 +33,6 @@ struct engine_helper * Boost.Random provides a vast choice of \generators as well * as \distributions. * - * Instantations of class template @c variate_generator model - * a \number_generator. - * * The argument for the template parameter Engine shall be of * the form U, U&, or U*, where U models a * \uniform_random_number_generator. Then, the member @@ -114,107 +51,72 @@ template class variate_generator { private: - typedef random::detail::pass_through_engine decorated_engine; - + typedef boost::random::detail::ptr_helper helper_type; public: - typedef typename decorated_engine::base_type engine_value_type; - typedef Engine engine_type; - typedef Distribution distribution_type; - typedef typename Distribution::result_type result_type; - - /** - * Constructs a @c variate_generator object with the associated - * \uniform_random_number_generator eng and the associated - * \random_distribution d. - * - * Throws: If and what the copy constructor of Engine or - * Distribution throws. - */ - variate_generator(Engine e, Distribution d) - : _eng(decorated_engine(e)), _dist(d) { } - - /** - * Returns: distribution()(e) - * - * Notes: The sequence of numbers produced by the - * \uniform_random_number_generator e, se, is - * obtained from the sequence of numbers produced by the - * associated \uniform_random_number_generator eng, seng, - * as follows: Consider the values of @c numeric_limits::is_integer - * for @c T both @c Distribution::input_type and - * @c engine_value_type::result_type. If the values for both types are - * true, then se is identical to seng. Otherwise, if the - * values for both types are false, then the numbers in seng - * are divided by engine().max()-engine().min() to obtain the numbers - * in se. Otherwise, if the value for - * @c engine_value_type::result_type is true and the value for - * @c Distribution::input_type is false, then the numbers in seng - * are divided by engine().max()-engine().min()+1 to obtain the numbers in - * se. Otherwise, the mapping from seng to - * se is implementation-defined. In all cases, an - * implicit conversion from @c engine_value_type::result_type to - * @c Distribution::input_type is performed. If such a conversion does - * not exist, the program is ill-formed. - */ - result_type operator()() { return _dist(_eng); } - /** - * Returns: distribution()(e, value). - * For the semantics of e, see the description of operator()(). - */ - template - result_type operator()(T value) { return _dist(_eng, value); } - - /** - * Returns: A reference to the associated uniform random number generator. - */ - engine_value_type& engine() { return _eng.base().base(); } - /** - * Returns: A reference to the associated uniform random number generator. - */ - const engine_value_type& engine() const { return _eng.base().base(); } - - /** - * Returns: A reference to the associated random distribution. - */ - distribution_type& distribution() { return _dist; } - /** - * Returns: A reference to the associated random distribution. - */ - const distribution_type& distribution() const { return _dist; } - - /** - * Precondition: distribution().min() is well-formed - * - * Returns: distribution().min() - */ - result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); } - /** - * Precondition: distribution().max() is well-formed - * - * Returns: distribution().max() - */ - result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); } + typedef typename helper_type::value_type engine_value_type; + typedef Engine engine_type; + typedef Distribution distribution_type; + typedef typename Distribution::result_type result_type; + + /** + * Constructs a @c variate_generator object with the associated + * \uniform_random_number_generator eng and the associated + * \random_distribution d. + * + * Throws: If and what the copy constructor of Engine or + * Distribution throws. + */ + variate_generator(Engine e, Distribution d) + : _eng(e), _dist(d) { } + + /** Returns: distribution()(engine()) */ + result_type operator()() { return _dist(engine()); } + /** + * Returns: distribution()(engine(), value). + */ + template + result_type operator()(const T& value) { return _dist(engine(), value); } + + /** + * Returns: A reference to the associated uniform random number generator. + */ + engine_value_type& engine() { return helper_type::ref(_eng); } + /** + * Returns: A reference to the associated uniform random number generator. + */ + const engine_value_type& engine() const { return helper_type::ref(_eng); } + + /** Returns: A reference to the associated \random_distribution. */ + distribution_type& distribution() { return _dist; } + /** + * Returns: A reference to the associated random distribution. + */ + const distribution_type& distribution() const { return _dist; } + + /** + * Precondition: distribution().min() is well-formed + * + * Returns: distribution().min() + */ + result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); } + /** + * Precondition: distribution().max() is well-formed + * + * Returns: distribution().max() + */ + result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); } private: -#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564) - typedef typename random::detail::engine_helper< - ::boost::is_integral::value, - ::boost::is_integral::value - >::BOOST_NESTED_TEMPLATE impl::type internal_engine_type; -#else - enum { - have_int = std::numeric_limits::is_integer, - want_int = std::numeric_limits::is_integer - }; - typedef typename random::detail::engine_helper::BOOST_NESTED_TEMPLATE impl::type internal_engine_type; -#endif - - internal_engine_type _eng; - distribution_type _dist; + Engine _eng; + distribution_type _dist; }; +} // namespace random + +using random::variate_generator; + } // namespace boost -#include +#include #endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP