epoc32/include/stdapis/boost/random/uniform_01.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/uniform_01.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,93 @@
     1.4 +/* boost random/uniform_01.hpp header file
     1.5 + *
     1.6 + * Copyright Jens Maurer 2000-2001
     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: uniform_01.hpp,v 1.18 2004/07/27 03:43:32 dgregor Exp $
    1.14 + *
    1.15 + * Revision history
    1.16 + *  2001-02-18  moved to individual header files
    1.17 + */
    1.18 +
    1.19 +#ifndef BOOST_RANDOM_UNIFORM_01_HPP
    1.20 +#define BOOST_RANDOM_UNIFORM_01_HPP
    1.21 +
    1.22 +#include <iostream>
    1.23 +#include <boost/config.hpp>
    1.24 +#include <boost/limits.hpp>
    1.25 +#include <boost/static_assert.hpp>
    1.26 +
    1.27 +namespace boost {
    1.28 +
    1.29 +// Because it is so commonly used: uniform distribution on the real [0..1)
    1.30 +// range.  This allows for specializations to avoid a costly int -> float
    1.31 +// conversion plus float multiplication
    1.32 +template<class UniformRandomNumberGenerator, class RealType = double>
    1.33 +class uniform_01
    1.34 +{
    1.35 +public:
    1.36 +  typedef UniformRandomNumberGenerator base_type;
    1.37 +  typedef RealType result_type;
    1.38 +
    1.39 +  BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
    1.40 +
    1.41 +#if !defined(BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS) && !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300)
    1.42 +  BOOST_STATIC_ASSERT(!std::numeric_limits<RealType>::is_integer);
    1.43 +#endif
    1.44 +
    1.45 +  explicit uniform_01(base_type rng)
    1.46 +    : _rng(rng),
    1.47 +      _factor(result_type(1) /
    1.48 +              (result_type((_rng.max)()-(_rng.min)()) +
    1.49 +               result_type(std::numeric_limits<base_result>::is_integer ? 1 : 0)))
    1.50 +  {
    1.51 +  }
    1.52 +  // compiler-generated copy ctor and copy assignment are fine
    1.53 +
    1.54 +  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(0); }
    1.55 +  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return result_type(1); }
    1.56 +  base_type& base() { return _rng; }
    1.57 +  const base_type& base() const { return _rng; }
    1.58 +  void reset() { }
    1.59 +
    1.60 +  result_type operator()() {
    1.61 +    return result_type(_rng() - (_rng.min)()) * _factor;
    1.62 +  }
    1.63 +
    1.64 +#if !defined(BOOST_NO_OPERATORS_IN_NAMESPACE) && !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
    1.65 +  template<class CharT, class Traits>
    1.66 +  friend std::basic_ostream<CharT,Traits>&
    1.67 +  operator<<(std::basic_ostream<CharT,Traits>& os, const uniform_01& u)
    1.68 +  {
    1.69 +    os << u._rng;
    1.70 +    return os;
    1.71 +  }
    1.72 +
    1.73 +  template<class CharT, class Traits>
    1.74 +  friend std::basic_istream<CharT,Traits>&
    1.75 +  operator>>(std::basic_istream<CharT,Traits>& is, uniform_01& u)
    1.76 +  {
    1.77 +    is >> u._rng;
    1.78 +    return is;
    1.79 +  }
    1.80 +#endif
    1.81 +
    1.82 +private:
    1.83 +  typedef typename base_type::result_type base_result;
    1.84 +  base_type _rng;
    1.85 +  result_type _factor;
    1.86 +};
    1.87 +
    1.88 +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
    1.89 +//  A definition is required even for integral static constants
    1.90 +template<class UniformRandomNumberGenerator, class RealType>
    1.91 +const bool uniform_01<UniformRandomNumberGenerator, RealType>::has_fixed_range;
    1.92 +#endif
    1.93 +
    1.94 +} // namespace boost
    1.95 +
    1.96 +#endif // BOOST_RANDOM_UNIFORM_01_HPP