epoc32/include/stdapis/boost/random/variate_generator.hpp
branchSymbian2
changeset 2 2fe1408b6811
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/epoc32/include/stdapis/boost/random/variate_generator.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,133 @@
     1.4 +/* boost random/variate_generator.hpp header file
     1.5 + *
     1.6 + * Copyright Jens Maurer 2002
     1.7 + * Distributed under the Boost Software License, Version 1.0. (See
     1.8 + * accompanying file LICENSE_1_0.txt or copy at
     1.9 + * http://www.boost.org/LICENSE_1_0.txt)
    1.10 + *
    1.11 + * See http://www.boost.org for most recent version including documentation.
    1.12 + *
    1.13 + * $Id: variate_generator.hpp,v 1.8 2005/02/14 11:53:50 johnmaddock Exp $
    1.14 + *
    1.15 + */
    1.16 +
    1.17 +#ifndef BOOST_RANDOM_RANDOM_GENERATOR_HPP
    1.18 +#define BOOST_RANDOM_RANDOM_GENERATOR_HPP
    1.19 +
    1.20 +#include <boost/config.hpp>
    1.21 +
    1.22 +// implementation details
    1.23 +#include <boost/detail/workaround.hpp>
    1.24 +#include <boost/random/uniform_01.hpp>
    1.25 +#include <boost/random/detail/pass_through_engine.hpp>
    1.26 +#include <boost/random/detail/uniform_int_float.hpp>
    1.27 +#include <boost/random/detail/ptr_helper.hpp>
    1.28 +
    1.29 +// Borland C++ 5.6.0 has problems using its numeric_limits traits as
    1.30 +// template parameters
    1.31 +#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
    1.32 +#include <boost/type_traits/is_integral.hpp>
    1.33 +#endif
    1.34 +
    1.35 +namespace boost {
    1.36 +
    1.37 +namespace random {
    1.38 +namespace detail {
    1.39 +
    1.40 +template<bool have_int, bool want_int>
    1.41 +struct engine_helper;
    1.42 +
    1.43 +// for consistency, always have two levels of decorations
    1.44 +template<>
    1.45 +struct engine_helper<true, true>
    1.46 +{
    1.47 +  template<class Engine, class DistInputType>
    1.48 +  struct impl
    1.49 +  {
    1.50 +    typedef pass_through_engine<Engine> type;
    1.51 +  };
    1.52 +};
    1.53 +
    1.54 +template<>
    1.55 +struct engine_helper<false, false>
    1.56 +{
    1.57 +  template<class Engine, class DistInputType>
    1.58 +  struct impl
    1.59 +  {
    1.60 +    typedef uniform_01<Engine, DistInputType> type;
    1.61 +  };
    1.62 +};
    1.63 +
    1.64 +template<>
    1.65 +struct engine_helper<true, false>
    1.66 +{
    1.67 +  template<class Engine, class DistInputType>
    1.68 +  struct impl
    1.69 +  {
    1.70 +    typedef uniform_01<Engine, DistInputType> type;
    1.71 +  };
    1.72 +};
    1.73 +
    1.74 +template<>
    1.75 +struct engine_helper<false, true>
    1.76 +{
    1.77 +  template<class Engine, class DistInputType>
    1.78 +  struct impl
    1.79 +  {
    1.80 +    typedef uniform_int_float<Engine, unsigned long> type;
    1.81 +  };
    1.82 +};
    1.83 +
    1.84 +} // namespace detail
    1.85 +} // namespace random
    1.86 +
    1.87 +
    1.88 +template<class Engine, class Distribution>
    1.89 +class variate_generator
    1.90 +{
    1.91 +private:
    1.92 +  typedef random::detail::pass_through_engine<Engine> decorated_engine;
    1.93 +
    1.94 +public:
    1.95 +  typedef typename decorated_engine::base_type engine_value_type;
    1.96 +  typedef Engine engine_type;
    1.97 +  typedef Distribution distribution_type;
    1.98 +  typedef typename Distribution::result_type result_type;
    1.99 +
   1.100 +  variate_generator(Engine e, Distribution d)
   1.101 +    : _eng(decorated_engine(e)), _dist(d) { }
   1.102 +
   1.103 +  result_type operator()() { return _dist(_eng); }
   1.104 +  template<class T>
   1.105 +  result_type operator()(T value) { return _dist(_eng, value); }
   1.106 +
   1.107 +  engine_value_type& engine() { return _eng.base().base(); }
   1.108 +  const engine_value_type& engine() const { return _eng.base().base(); }
   1.109 +
   1.110 +  distribution_type& distribution() { return _dist; }
   1.111 +  const distribution_type& distribution() const { return _dist; }
   1.112 +
   1.113 +  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().min)(); }
   1.114 +  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (distribution().max)(); }
   1.115 +
   1.116 +private:
   1.117 +#if BOOST_WORKAROUND(__BORLANDC__, <= 0x564)
   1.118 +  typedef typename random::detail::engine_helper<
   1.119 +    boost::is_integral<typename decorated_engine::result_type>::value,
   1.120 +    boost::is_integral<typename Distribution::input_type>::value
   1.121 +    >::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
   1.122 +#else
   1.123 +  enum {
   1.124 +    have_int = std::numeric_limits<typename decorated_engine::result_type>::is_integer,
   1.125 +    want_int = std::numeric_limits<typename Distribution::input_type>::is_integer
   1.126 +  };
   1.127 +  typedef typename random::detail::engine_helper<have_int, want_int>::BOOST_NESTED_TEMPLATE impl<decorated_engine, typename Distribution::input_type>::type internal_engine_type;
   1.128 +#endif
   1.129 +
   1.130 +  internal_engine_type _eng;
   1.131 +  distribution_type _dist;
   1.132 +};
   1.133 +
   1.134 +} // namespace boost
   1.135 +
   1.136 +#endif // BOOST_RANDOM_RANDOM_GENERATOR_HPP