fix doc example typo
[boost.git] / boost / property_map / property_map_iterator.hpp
bloba7be8afecfc8d9993f2745d0fdba23abb59b640c
1 // (C) Copyright Jeremy Siek, 2001.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 // See http://www.boost.org/libs/property_map for documentation.
8 #ifndef BOOST_PROPERTY_MAP_ITERATOR_HPP
9 #define BOOST_PROPERTY_MAP_ITERATOR_HPP
11 #include <boost/property_map/property_map.hpp>
12 #include <boost/iterator/iterator_adaptor.hpp>
13 #include <boost/mpl/if.hpp>
14 #include <boost/type_traits/is_same.hpp>
16 namespace boost {
18 //======================================================================
19 // property iterator, generalized from ideas by Francois Faure
21 namespace detail {
23 template <class Iterator, class LvaluePropertyMap>
24 class lvalue_pmap_iter
25 : public iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
26 Iterator,
27 typename property_traits<LvaluePropertyMap>::value_type,
28 use_default,
29 typename property_traits<LvaluePropertyMap>::reference>
31 friend class boost::iterator_core_access;
33 typedef iterator_adaptor< lvalue_pmap_iter< Iterator, LvaluePropertyMap >,
34 Iterator,
35 typename property_traits<LvaluePropertyMap>::value_type,
36 use_default,
37 typename property_traits<LvaluePropertyMap>::reference> super_t;
39 public:
40 lvalue_pmap_iter() { }
41 lvalue_pmap_iter(Iterator const& it,
42 LvaluePropertyMap m)
43 : super_t(it),
44 m_map(m) {}
46 private:
47 typename super_t::reference
48 dereference() const
50 return m_map[*(this->base_reference())];
53 LvaluePropertyMap m_map;
56 template <class Iterator, class ReadablePropertyMap>
57 class readable_pmap_iter :
58 public iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
59 Iterator,
60 typename property_traits<ReadablePropertyMap>::value_type,
61 use_default,
62 typename property_traits<ReadablePropertyMap>::value_type>
66 friend class boost::iterator_core_access;
68 typedef iterator_adaptor< readable_pmap_iter< Iterator, ReadablePropertyMap >,
69 Iterator,
70 typename property_traits<ReadablePropertyMap>::value_type,
71 use_default,
72 typename property_traits<ReadablePropertyMap>::value_type> super_t;
74 public:
75 readable_pmap_iter() { }
76 readable_pmap_iter(Iterator const& it,
77 ReadablePropertyMap m)
78 : super_t(it),
79 m_map(m) {}
81 private:
82 typename super_t::reference
83 dereference() const
85 return get(m_map, *(this->base_reference()));
88 ReadablePropertyMap m_map;
92 } // namespace detail
94 template <class PropertyMap, class Iterator>
95 struct property_map_iterator_generator :
96 mpl::if_< is_same< typename property_traits<PropertyMap>::category, lvalue_property_map_tag>,
97 detail::lvalue_pmap_iter<Iterator, PropertyMap>,
98 detail::readable_pmap_iter<Iterator, PropertyMap> >
99 {};
101 template <class PropertyMap, class Iterator>
102 typename property_map_iterator_generator<PropertyMap, Iterator>::type
103 make_property_map_iterator(PropertyMap pmap, Iterator iter)
105 typedef typename property_map_iterator_generator<PropertyMap,
106 Iterator>::type Iter;
107 return Iter(iter, pmap);
110 } // namespace boost
112 #endif // BOOST_PROPERTY_MAP_ITERATOR_HPP