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 18 namespace boost { 19 20 // must be in boost namespace, otherwise the inline friend trick fails 21 template<class Generator, class ResultType> 22 class generator_iterator_mixin_adapter 23 : incrementable<Generator>, equality_comparable<Generator> 24 { 25 public: 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; operator ++()31 Generator& operator++() { v = cast()(); return cast(); } operator *() const32 const value_type& operator*() const { return v; } 33 34 protected: 35 // instantiate from derived classes only generator_iterator_mixin_adapter()36 generator_iterator_mixin_adapter() { } iterator_init()37 void iterator_init() { operator++(); } 38 private: cast()39 Generator & cast() { return static_cast<Generator&>(*this); } 40 value_type v; 41 }; 42 43 } // namespace boost 44 45 #endif // BOOST_ITERATOR_MIXIN_HPP 46