/src/contrib/boost/random/detail/pass_through_engine.hpp

http://pythonocc.googlecode.com/ · C++ Header · 100 lines · 67 code · 20 blank · 13 comment · 0 complexity · 718e3b2fe72e678fe4ca3bf67a7ae112 MD5 · raw file

  1. /* boost random/detail/uniform_int_float.hpp header file
  2. *
  3. * Copyright Jens Maurer 2000-2001
  4. * Distributed under the Boost Software License, Version 1.0. (See
  5. * accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * See http://www.boost.org for most recent version including documentation.
  9. *
  10. * $Id: pass_through_engine.hpp 58649 2010-01-02 21:23:17Z steven_watanabe $
  11. *
  12. */
  13. #ifndef BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
  14. #define BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
  15. #include <boost/config.hpp>
  16. #include <boost/random/detail/ptr_helper.hpp>
  17. #include <boost/random/detail/disable_warnings.hpp>
  18. namespace boost {
  19. namespace random {
  20. namespace detail {
  21. template<class UniformRandomNumberGenerator>
  22. class pass_through_engine
  23. {
  24. private:
  25. typedef ptr_helper<UniformRandomNumberGenerator> helper_type;
  26. public:
  27. typedef typename helper_type::value_type base_type;
  28. typedef typename base_type::result_type result_type;
  29. explicit pass_through_engine(UniformRandomNumberGenerator rng)
  30. // make argument an rvalue to avoid matching Generator& constructor
  31. : _rng(static_cast<typename helper_type::rvalue_type>(rng))
  32. { }
  33. result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().min)(); }
  34. result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().max)(); }
  35. base_type& base() { return helper_type::ref(_rng); }
  36. const base_type& base() const { return helper_type::ref(_rng); }
  37. result_type operator()() { return base()(); }
  38. private:
  39. UniformRandomNumberGenerator _rng;
  40. };
  41. #ifndef BOOST_NO_STD_LOCALE
  42. template<class UniformRandomNumberGenerator, class CharT, class Traits>
  43. std::basic_ostream<CharT,Traits>&
  44. operator<<(
  45. std::basic_ostream<CharT,Traits>& os
  46. , const pass_through_engine<UniformRandomNumberGenerator>& ud
  47. )
  48. {
  49. return os << ud.base();
  50. }
  51. template<class UniformRandomNumberGenerator, class CharT, class Traits>
  52. std::basic_istream<CharT,Traits>&
  53. operator>>(
  54. std::basic_istream<CharT,Traits>& is
  55. , const pass_through_engine<UniformRandomNumberGenerator>& ud
  56. )
  57. {
  58. return is >> ud.base();
  59. }
  60. #else // no new streams
  61. template<class UniformRandomNumberGenerator>
  62. inline std::ostream&
  63. operator<<(std::ostream& os,
  64. const pass_through_engine<UniformRandomNumberGenerator>& ud)
  65. {
  66. return os << ud.base();
  67. }
  68. template<class UniformRandomNumberGenerator>
  69. inline std::istream&
  70. operator>>(std::istream& is,
  71. const pass_through_engine<UniformRandomNumberGenerator>& ud)
  72. {
  73. return is >> ud.base();
  74. }
  75. #endif
  76. } // namespace detail
  77. } // namespace random
  78. } // namespace boost
  79. #include <boost/random/detail/enable_warnings.hpp>
  80. #endif // BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP