iterator_traits.qbk 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. [section:iterator_traits Iterator Traits]
  2. `std::iterator_traits` provides access to five associated types
  3. of any iterator: its `value_type`, `reference`, `pointer`,
  4. `iterator_category`, and `difference_type`. Unfortunately,
  5. such a "multi-valued" traits template can be difficult to use in a
  6. metaprogramming context. `<boost/iterator/iterator_traits.hpp>`
  7. provides access to these types using a standard metafunctions_.
  8. [h2 Synopsis]
  9. Header `<boost/iterator/iterator_traits.hpp>`:
  10. template <class Iterator>
  11. struct iterator_value
  12. {
  13. typedef typename
  14. std::iterator_traits<Iterator>::value_type
  15. type;
  16. };
  17. template <class Iterator>
  18. struct iterator_reference
  19. {
  20. typedef typename
  21. std::iterator_traits<Iterator>::reference
  22. type;
  23. };
  24. template <class Iterator>
  25. struct iterator_pointer
  26. {
  27. typedef typename
  28. std::iterator_traits<Iterator>::pointer
  29. type;
  30. };
  31. template <class Iterator>
  32. struct iterator_difference
  33. {
  34. typedef typename
  35. detail::iterator_traits<Iterator>::difference_type
  36. type;
  37. };
  38. template <class Iterator>
  39. struct iterator_category
  40. {
  41. typedef typename
  42. detail::iterator_traits<Iterator>::iterator_category
  43. type;
  44. };
  45. [endsect]