1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
8 #include <vector>
9 #include <string>
10 #include <boost/property_map/property_map.hpp>
11 #include <boost/concept/assert.hpp>
12
13 #ifdef BOOST_NO_STD_ITERATOR_TRAITS
14 #error This examples requires a compiler that provides a working std::iterator_traits
15 #endif
16
17 namespace foo
18 {
19 using namespace boost;
20 template < class RandomAccessIterator, class IndexMap >
21 class iterator_property_map
22 : public boost::put_get_helper<
23 typename std::iterator_traits< RandomAccessIterator >::reference,
24 iterator_property_map< RandomAccessIterator, IndexMap > >
25 {
26 public:
27 typedef std::ptrdiff_t key_type;
28 typedef typename std::iterator_traits< RandomAccessIterator >::value_type
29 value_type;
30 typedef typename std::iterator_traits< RandomAccessIterator >::reference
31 reference;
32 typedef boost::lvalue_property_map_tag category;
33
iterator_property_map(RandomAccessIterator cc=RandomAccessIterator (),const IndexMap & _id=IndexMap ())34 iterator_property_map(RandomAccessIterator cc = RandomAccessIterator(),
35 const IndexMap& _id = IndexMap())
36 : iter(cc), index(_id)
37 {
38 }
operator [](std::ptrdiff_t v) const39 reference operator[](std::ptrdiff_t v) const
40 {
41 return *(iter + get(index, v));
42 }
43
44 protected:
45 RandomAccessIterator iter;
46 IndexMap index;
47 };
48
49 }
50
main()51 int main()
52 {
53 typedef std::vector< std::string > vec_t;
54 typedef foo::iterator_property_map< vec_t::iterator,
55 boost::identity_property_map >
56 pmap_t;
57 using namespace boost;
58 BOOST_CONCEPT_ASSERT((Mutable_LvaluePropertyMapConcept< pmap_t, int >));
59 return 0;
60 }
61