/Src/Dependencies/Boost/libs/iterator/doc/iterator_traits.rst

http://hadesmem.googlecode.com/ · ReStructuredText · 98 lines · 77 code · 21 blank · 0 comment · 0 complexity · dba2f386289026b2725684ac03132e5a MD5 · raw file

  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: 2008-03-23 08:45:55 +1100 (Sun, 23 Mar 2008) $
  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. };
  63. Broken Compiler Notes
  64. =====================
  65. Because of workarounds in Boost, you may find that these
  66. metafunctions_ actually work better than the facilities provided by
  67. your compiler's standard library.
  68. On compilers that don't support partial specialization, such as
  69. Microsoft Visual C++ 6.0 or 7.0, you may need to manually invoke
  70. BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION_ on the
  71. ``value_type`` of pointers that are passed to these metafunctions.
  72. Because of bugs in the implementation of GCC-2.9x, the name of
  73. ``iterator_category`` is changed to ``iterator_category_`` on that
  74. compiler. A macro, ``BOOST_ITERATOR_CATEGORY``, that expands to
  75. either ``iterator_category`` or ``iterator_category_``, as
  76. appropriate to the platform, is provided for portability.
  77. .. _BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION: ../../type_traits/index.html#transformations