source: NonGTP/Boost/boost/random/detail/iterator_mixin.hpp @ 857

Revision 857, 1.3 KB checked in by igarcia, 19 years ago (diff)
Line 
1/* boost random/detail/iterator_mixin.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 * Revision history
11 */
12
13#ifndef BOOST_ITERATOR_MIXIN_HPP
14#define BOOST_ITERATOR_MIXIN_HPP
15
16#include <boost/operators.hpp>
17
18namespace boost {
19
20// must be in boost namespace, otherwise the inline friend trick fails
21template<class Generator, class ResultType>
22class generator_iterator_mixin_adapter
23  : incrementable<Generator>, equality_comparable<Generator>
24{
25public:
26  typedef std::input_iterator_tag iterator_category;
27  typedef ResultType value_type;
28  typedef std::ptrdiff_t difference_type;
29  typedef const value_type * pointer;
30  typedef const value_type & reference;
31  Generator& operator++() { v = cast()(); return cast(); }
32  const value_type& operator*() const { return v; }
33
34protected:
35  // instantiate from derived classes only
36  generator_iterator_mixin_adapter() { }
37  void iterator_init() { operator++(); }
38private:
39  Generator & cast() { return static_cast<Generator&>(*this); }
40  value_type v;
41};
42
43} // namespace boost
44
45#endif // BOOST_ITERATOR_MIXIN_HPP
Note: See TracBrowser for help on using the repository browser.