epoc32/include/stdapis/boost/random/discard_block.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/discard_block.hpp	Tue Mar 16 16:12:26 2010 +0000
     1.3 @@ -0,0 +1,121 @@
     1.4 +/* boost random/discard_block.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: discard_block.hpp,v 1.12 2005/05/21 15:57:00 dgregor Exp $
    1.14 + *
    1.15 + * Revision history
    1.16 + *  2001-03-02  created
    1.17 + */
    1.18 +
    1.19 +#ifndef BOOST_RANDOM_DISCARD_BLOCK_HPP
    1.20 +#define BOOST_RANDOM_DISCARD_BLOCK_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 +
    1.28 +namespace boost {
    1.29 +namespace random {
    1.30 +
    1.31 +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
    1.32 +class discard_block
    1.33 +{
    1.34 +public:
    1.35 +  typedef UniformRandomNumberGenerator base_type;
    1.36 +  typedef typename base_type::result_type result_type;
    1.37 +
    1.38 +  BOOST_STATIC_CONSTANT(bool, has_fixed_range = false);
    1.39 +  BOOST_STATIC_CONSTANT(unsigned int, total_block = p);
    1.40 +  BOOST_STATIC_CONSTANT(unsigned int, returned_block = r);
    1.41 +
    1.42 +#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
    1.43 +  BOOST_STATIC_ASSERT(total_block >= returned_block);
    1.44 +#endif
    1.45 +
    1.46 +  discard_block() : _rng(), _n(0) { }
    1.47 +  explicit discard_block(const base_type & rng) : _rng(rng), _n(0) { }
    1.48 +  template<class It> discard_block(It& first, It last)
    1.49 +    : _rng(first, last), _n(0) { }
    1.50 +  void seed() { _rng.seed(); _n = 0; }
    1.51 +  template<class T> void seed(T s) { _rng.seed(s); _n = 0; }
    1.52 +  template<class It> void seed(It& first, It last)
    1.53 +  { _n = 0; _rng.seed(first, last); }
    1.54 +
    1.55 +  const base_type& base() const { return _rng; }
    1.56 +
    1.57 +  result_type operator()()
    1.58 +  {
    1.59 +    if(_n >= returned_block) {
    1.60 +      // discard values of random number generator
    1.61 +      for( ; _n < total_block; ++_n)
    1.62 +        _rng();
    1.63 +      _n = 0;
    1.64 +    }
    1.65 +    ++_n;
    1.66 +    return _rng();
    1.67 +  }
    1.68 +
    1.69 +  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.min)(); }
    1.70 +  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (_rng.max)(); }
    1.71 +  static bool validation(result_type x) { return true; }  // dummy
    1.72 +
    1.73 +#ifndef BOOST_NO_OPERATORS_IN_NAMESPACE
    1.74 +
    1.75 +#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
    1.76 +  template<class CharT, class Traits>
    1.77 +  friend std::basic_ostream<CharT,Traits>&
    1.78 +  operator<<(std::basic_ostream<CharT,Traits>& os, const discard_block& s)
    1.79 +  {
    1.80 +    os << s._rng << " " << s._n << " ";
    1.81 +    return os;
    1.82 +  }
    1.83 +
    1.84 +  template<class CharT, class Traits>
    1.85 +  friend std::basic_istream<CharT,Traits>&
    1.86 +  operator>>(std::basic_istream<CharT,Traits>& is, discard_block& s)
    1.87 +  {
    1.88 +    is >> s._rng >> std::ws >> s._n >> std::ws;
    1.89 +    return is;
    1.90 +  }
    1.91 +#endif
    1.92 +
    1.93 +  friend bool operator==(const discard_block& x, const discard_block& y)
    1.94 +  { return x._rng == y._rng && x._n == y._n; }
    1.95 +  friend bool operator!=(const discard_block& x, const discard_block& y)
    1.96 +  { return !(x == y); }
    1.97 +#else
    1.98 +  // Use a member function; Streamable concept not supported.
    1.99 +  bool operator==(const discard_block& rhs) const
   1.100 +  { return _rng == rhs._rng && _n == rhs._n; }
   1.101 +  bool operator!=(const discard_block& rhs) const
   1.102 +  { return !(*this == rhs); }
   1.103 +#endif
   1.104 +
   1.105 +private:
   1.106 +  base_type _rng;
   1.107 +  unsigned int _n;
   1.108 +};
   1.109 +
   1.110 +#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
   1.111 +//  A definition is required even for integral static constants
   1.112 +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
   1.113 +const bool discard_block<UniformRandomNumberGenerator, p, r>::has_fixed_range;
   1.114 +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
   1.115 +const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::total_block;
   1.116 +template<class UniformRandomNumberGenerator, unsigned int p, unsigned int r>
   1.117 +const unsigned int discard_block<UniformRandomNumberGenerator, p, r>::returned_block;
   1.118 +#endif
   1.119 +
   1.120 +} // namespace random
   1.121 +
   1.122 +} // namespace boost
   1.123 +
   1.124 +#endif // BOOST_RANDOM_DISCARD_BLOCK_HPP