node_iterator2.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_ITERATOR2_DWA2004110_HPP
  5. # define NODE_ITERATOR2_DWA2004110_HPP
  6. # include "node.hpp"
  7. # include <boost/iterator/iterator_facade.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_facade<
  15. node_iter<Value>
  16. , Value
  17. , boost::forward_traversal_tag
  18. >
  19. {
  20. private:
  21. struct enabler {}; // a private type avoids misuse
  22. public:
  23. node_iter()
  24. : m_node(0) {}
  25. explicit node_iter(Value* p)
  26. : m_node(p) {}
  27. template <class OtherValue>
  28. node_iter(
  29. node_iter<OtherValue> const& other
  30. # ifndef BOOST_NO_SFINAE
  31. , typename boost::enable_if<
  32. boost::is_convertible<OtherValue*,Value*>
  33. , enabler
  34. >::type = enabler()
  35. # endif
  36. )
  37. : m_node(other.m_node) {}
  38. # if !BOOST_WORKAROUND(__GNUC__, == 2)
  39. private: // GCC2 can't grant friendship to template member functions
  40. friend class boost::iterator_core_access;
  41. # endif
  42. template <class OtherValue>
  43. bool equal(node_iter<OtherValue> const& other) const
  44. {
  45. return this->m_node == other.m_node;
  46. }
  47. void increment() { m_node = m_node->next(); }
  48. Value& dereference() const { return *m_node; }
  49. # ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  50. public:
  51. # else
  52. private:
  53. template <class> friend class node_iter;
  54. # endif
  55. Value* m_node;
  56. };
  57. typedef node_iter<node_base> node_iterator;
  58. typedef node_iter<node_base const> node_const_iterator;
  59. #endif // NODE_ITERATOR2_DWA2004110_HPP