put-get-helper-eg.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #ifdef BOOST_NO_STD_ITERATOR_TRAITS
  13. #error This examples requires a compiler that provides a working std::iterator_traits
  14. #endif
  15. namespace foo
  16. {
  17. using namespace boost;
  18. template < class RandomAccessIterator, class IndexMap >
  19. class iterator_property_map:public boost::put_get_helper <
  20. typename std::iterator_traits < RandomAccessIterator >::reference,
  21. iterator_property_map < RandomAccessIterator, IndexMap > >
  22. {
  23. public:
  24. typedef std::ptrdiff_t key_type;
  25. typedef typename std::iterator_traits < RandomAccessIterator >::value_type
  26. value_type;
  27. typedef typename std::iterator_traits < RandomAccessIterator >::reference
  28. reference;
  29. typedef boost::lvalue_property_map_tag category;
  30. iterator_property_map(RandomAccessIterator cc = RandomAccessIterator(),
  31. const IndexMap & _id =
  32. IndexMap()):iter(cc), index(_id)
  33. {
  34. }
  35. reference operator[] (std::ptrdiff_t v) const
  36. {
  37. return *(iter + get(index, v));
  38. }
  39. protected:
  40. RandomAccessIterator iter;
  41. IndexMap index;
  42. };
  43. }
  44. int
  45. main()
  46. {
  47. typedef std::vector < std::string > vec_t;
  48. typedef foo::iterator_property_map < vec_t::iterator,
  49. boost::identity_property_map > pmap_t;
  50. using namespace boost;
  51. BOOST_CONCEPT_ASSERT(( Mutable_LvaluePropertyMapConcept<pmap_t, int> ));
  52. return 0;
  53. }