Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/boost/random/detail/pass_through_engine.hpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.6 KB
Line 
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,v 1.5 2004/07/27 03:43:32 dgregor Exp $
11 *
12 */
13
14#ifndef BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
15#define BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
16
17#include <boost/config.hpp>
18#include <boost/random/detail/ptr_helper.hpp>
19
20
21namespace boost {
22namespace random {
23namespace detail {
24
25template<class UniformRandomNumberGenerator>
26class pass_through_engine
27{
28private:
29  typedef ptr_helper<UniformRandomNumberGenerator> helper_type;
30
31public:
32  typedef typename helper_type::value_type base_type;
33  typedef typename base_type::result_type result_type;
34
35  explicit pass_through_engine(UniformRandomNumberGenerator rng)
36    // make argument an rvalue to avoid matching Generator& constructor
37    : _rng(static_cast<typename helper_type::rvalue_type>(rng))
38  { }
39
40  result_type min BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().min)(); }
41  result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().max)(); }
42  base_type& base() { return helper_type::ref(_rng); }
43  const base_type& base() const { return helper_type::ref(_rng); }
44
45  result_type operator()() { return base()(); }
46
47private:
48  UniformRandomNumberGenerator _rng;
49};
50
51#ifndef BOOST_NO_STD_LOCALE
52
53template<class UniformRandomNumberGenerator, class CharT, class Traits>
54std::basic_ostream<CharT,Traits>&
55operator<<(
56    std::basic_ostream<CharT,Traits>& os
57    , const pass_through_engine<UniformRandomNumberGenerator>& ud
58    )
59{
60    return os << ud.base();
61}
62
63template<class UniformRandomNumberGenerator, class CharT, class Traits>
64std::basic_istream<CharT,Traits>&
65operator>>(
66    std::basic_istream<CharT,Traits>& is
67    , const pass_through_engine<UniformRandomNumberGenerator>& ud
68    )
69{
70    return is >> ud.base();
71}
72
73#else // no new streams
74
75template<class UniformRandomNumberGenerator>
76inline std::ostream&
77operator<<(std::ostream& os, 
78           const pass_through_engine<UniformRandomNumberGenerator>& ud)
79{
80    return os << ud.base();
81}
82
83template<class UniformRandomNumberGenerator>
84inline std::istream&
85operator>>(std::istream& is, 
86           const pass_through_engine<UniformRandomNumberGenerator>& ud)
87{
88    return is >> ud.base();
89}
90
91#endif
92
93} // namespace detail
94} // namespace random
95} // namespace boost
96
97#endif // BOOST_RANDOM_DETAIL_PASS_THROUGH_ENGINE_HPP
98
Note: See TracBrowser for help on using the repository browser.