/Src/Dependencies/Boost/boost/random/detail/iterator_mixin.hpp

http://hadesmem.googlecode.com/ · C++ Header · 45 lines · 25 code · 7 blank · 13 comment · 0 complexity · b0a61adb110452dd4315860266bf0e3c MD5 · raw file

  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. #ifndef BOOST_ITERATOR_MIXIN_HPP
  13. #define BOOST_ITERATOR_MIXIN_HPP
  14. #include <boost/operators.hpp>
  15. namespace boost {
  16. // must be in boost namespace, otherwise the inline friend trick fails
  17. template<class Generator, class ResultType>
  18. class generator_iterator_mixin_adapter
  19. : incrementable<Generator>, equality_comparable<Generator>
  20. {
  21. public:
  22. typedef std::input_iterator_tag iterator_category;
  23. typedef ResultType value_type;
  24. typedef std::ptrdiff_t difference_type;
  25. typedef const value_type * pointer;
  26. typedef const value_type & reference;
  27. Generator& operator++() { v = cast()(); return cast(); }
  28. const value_type& operator*() const { return v; }
  29. protected:
  30. // instantiate from derived classes only
  31. generator_iterator_mixin_adapter() { }
  32. void iterator_init() { operator++(); }
  33. private:
  34. Generator & cast() { return static_cast<Generator&>(*this); }
  35. value_type v;
  36. };
  37. } // namespace boost
  38. #endif // BOOST_ITERATOR_MIXIN_HPP