node_iterator3.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright David Abrahams 2004. Use, modification and distribution is
  2. // subject to the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef NODE_ITERATOR3_DWA2004110_HPP
  5. # define NODE_ITERATOR3_DWA2004110_HPP
  6. # include "node.hpp"
  7. # include <boost/iterator/iterator_adaptor.hpp>
  8. # ifndef BOOST_NO_SFINAE
  9. # include <boost/type_traits/is_convertible.hpp>
  10. # include <boost/utility/enable_if.hpp>
  11. # endif
  12. template <class Value>
  13. class node_iter
  14. : public boost::iterator_adaptor<
  15. node_iter<Value> // Derived
  16. , Value* // Base
  17. , boost::use_default // Value
  18. , boost::forward_traversal_tag // CategoryOrTraversal
  19. >
  20. {
  21. private:
  22. struct enabler {}; // a private type avoids misuse
  23. typedef boost::iterator_adaptor<
  24. node_iter<Value>, Value*, boost::use_default, boost::forward_traversal_tag
  25. > super_t;
  26. public:
  27. node_iter()
  28. : super_t(0) {}
  29. explicit node_iter(Value* p)
  30. : super_t(p) {}
  31. template <class OtherValue>
  32. node_iter(
  33. node_iter<OtherValue> const& other
  34. # ifndef BOOST_NO_SFINAE
  35. , typename boost::enable_if<
  36. boost::is_convertible<OtherValue*,Value*>
  37. , enabler
  38. >::type = enabler()
  39. # endif
  40. )
  41. : super_t(other.base()) {}
  42. # if !BOOST_WORKAROUND(__GNUC__, == 2)
  43. private: // GCC2 can't grant friendship to template member functions
  44. friend class boost::iterator_core_access;
  45. # endif
  46. void increment() { this->base_reference() = this->base()->next(); }
  47. };
  48. typedef node_iter<node_base> node_iterator;
  49. typedef node_iter<node_base const> node_const_iterator;
  50. #endif // NODE_ITERATOR3_DWA2004110_HPP