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
18 namespace foo
19 {
20 using namespace boost;
21 template < class RandomAccessIterator, class IndexMap >
22 class iterator_property_map: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 =
36 IndexMap()):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 protected:
44 RandomAccessIterator iter;
45 IndexMap index;
46 };
47
48 }
49
50 int
main()51 main()
52 {
53 typedef std::vector < std::string > vec_t;
54 typedef foo::iterator_property_map < vec_t::iterator,
55 boost::identity_property_map > pmap_t;
56 using namespace boost;
57 BOOST_CONCEPT_ASSERT(( Mutable_LvaluePropertyMapConcept<pmap_t, int> ));
58 return 0;
59 }
60