• 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_ITERATOR3_DWA2004110_HPP
5 # define NODE_ITERATOR3_DWA2004110_HPP
6 
7 # include "node.hpp"
8 # include <boost/iterator/iterator_adaptor.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_adaptor<
18         node_iter<Value>                // Derived
19       , Value*                          // Base
20       , boost::use_default              // Value
21       , boost::forward_traversal_tag    // CategoryOrTraversal
22     >
23 {
24  private:
25     struct enabler {};  // a private type avoids misuse
26 
27     typedef boost::iterator_adaptor<
28         node_iter<Value>, Value*, boost::use_default, boost::forward_traversal_tag
29     > super_t;
30 
31  public:
node_iter()32     node_iter()
33       : super_t(0) {}
34 
node_iter(Value * p)35     explicit node_iter(Value* p)
36       : super_t(p) {}
37 
38     template <class OtherValue>
node_iter(node_iter<OtherValue> const & other,typename boost::enable_if<boost::is_convertible<OtherValue *,Value * >,enabler>::type=enabler ())39     node_iter(
40         node_iter<OtherValue> const& other
41 # ifndef BOOST_NO_SFINAE
42       , typename boost::enable_if<
43             boost::is_convertible<OtherValue*,Value*>
44           , enabler
45         >::type = enabler()
46 # endif
47     )
48       : super_t(other.base()) {}
49 
50 # if !BOOST_WORKAROUND(__GNUC__, == 2)
51  private: // GCC2 can't grant friendship to template member functions
52     friend class boost::iterator_core_access;
53 # endif
increment()54     void increment() { this->base_reference() = this->base()->next(); }
55 };
56 
57 typedef node_iter<node_base> node_iterator;
58 typedef node_iter<node_base const> node_const_iterator;
59 
60 #endif // NODE_ITERATOR3_DWA2004110_HPP
61