• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 # include "node.hpp"
8 # include <boost/iterator/iterator_facade.hpp>
9 
10 # ifndef BOOST_NO_SFINAE
11 #  include <boost/type_traits/is_convertible.hpp>
12 #  include <boost/utility/enable_if.hpp>
13 # endif
14 
15 template <class Value>
16 class node_iter
17   : public boost::iterator_facade<
18         node_iter<Value>
19       , Value
20       , boost::forward_traversal_tag
21     >
22 {
23  private:
24     struct enabler {};  // a private type avoids misuse
25 
26  public:
node_iter()27     node_iter()
28       : m_node(0) {}
29 
node_iter(Value * p)30     explicit node_iter(Value* p)
31       : m_node(p) {}
32 
33     template <class OtherValue>
node_iter(node_iter<OtherValue> const & other,typename boost::enable_if<boost::is_convertible<OtherValue *,Value * >,enabler>::type=enabler ())34     node_iter(
35         node_iter<OtherValue> const& other
36 # ifndef BOOST_NO_SFINAE
37       , typename boost::enable_if<
38             boost::is_convertible<OtherValue*,Value*>
39           , enabler
40         >::type = enabler()
41 # endif
42     )
43       : m_node(other.m_node) {}
44 
45 
46 # if !BOOST_WORKAROUND(__GNUC__, == 2)
47  private: // GCC2 can't grant friendship to template member functions
48     friend class boost::iterator_core_access;
49 # endif
50 
51     template <class OtherValue>
equal(node_iter<OtherValue> const & other) const52     bool equal(node_iter<OtherValue> const& other) const
53     {
54         return this->m_node == other.m_node;
55     }
56 
increment()57     void increment() { m_node = m_node->next(); }
58 
dereference() const59     Value& dereference() const { return *m_node; }
60 
61 # ifdef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
62  public:
63 # else
64  private:
65     template <class> friend class node_iter;
66 # endif
67     Value* m_node;
68 };
69 
70 typedef node_iter<node_base> node_iterator;
71 typedef node_iter<node_base const> node_const_iterator;
72 
73 #endif // NODE_ITERATOR2_DWA2004110_HPP
74