iterator_traits.rst 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. .. Distributed under the Boost
  2. .. Software License, Version 1.0. (See accompanying
  3. .. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. +++++++++++++++++
  5. Iterator Traits
  6. +++++++++++++++++
  7. :Author: David Abrahams
  8. :Contact: dave@boost-consulting.com
  9. :organization: `Boost Consulting`_
  10. :date: $Date$
  11. :copyright: Copyright David Abrahams 2004.
  12. .. _`Boost Consulting`: http://www.boost-consulting.com
  13. :abstract: Header ``<boost/iterator/iterator_traits.hpp>`` provides
  14. the ability to access an iterator's associated types using
  15. MPL-compatible metafunctions_.
  16. .. _metafunctions: ../../mpl/doc/index.html#metafunctions
  17. Overview
  18. ========
  19. ``std::iterator_traits`` provides access to five associated types
  20. of any iterator: its ``value_type``, ``reference``, ``pointer``,
  21. ``iterator_category``, and ``difference_type``. Unfortunately,
  22. such a "multi-valued" traits template can be difficult to use in a
  23. metaprogramming context. ``<boost/iterator/iterator_traits.hpp>``
  24. provides access to these types using a standard metafunctions_.
  25. Summary
  26. =======
  27. Header ``<boost/iterator/iterator_traits.hpp>``::
  28. template <class Iterator>
  29. struct iterator_value
  30. {
  31. typedef typename
  32. std::iterator_traits<Iterator>::value_type
  33. type;
  34. };
  35. template <class Iterator>
  36. struct iterator_reference
  37. {
  38. typedef typename
  39. std::iterator_traits<Iterator>::reference
  40. type;
  41. };
  42. template <class Iterator>
  43. struct iterator_pointer
  44. {
  45. typedef typename
  46. std::iterator_traits<Iterator>::pointer
  47. type;
  48. };
  49. template <class Iterator>
  50. struct iterator_difference
  51. {
  52. typedef typename
  53. detail::iterator_traits<Iterator>::difference_type
  54. type;
  55. };
  56. template <class Iterator>
  57. struct iterator_category
  58. {
  59. typedef typename
  60. detail::iterator_traits<Iterator>::iterator_category
  61. type;
  62. };