zip_iterator_ref.rst 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. .. Copyright David Abrahams 2006. 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. template<typename IteratorTuple>
  6. class zip_iterator
  7. {
  8. public:
  9. typedef /* see below */ reference;
  10. typedef reference value_type;
  11. typedef value_type* pointer;
  12. typedef /* see below */ difference_type;
  13. typedef /* see below */ iterator_category;
  14. zip_iterator();
  15. zip_iterator(IteratorTuple iterator_tuple);
  16. template<typename OtherIteratorTuple>
  17. zip_iterator(
  18. const zip_iterator<OtherIteratorTuple>& other
  19. , typename enable_if_convertible<
  20. OtherIteratorTuple
  21. , IteratorTuple>::type* = 0 // exposition only
  22. );
  23. const IteratorTuple& get_iterator_tuple() const;
  24. private:
  25. IteratorTuple m_iterator_tuple; // exposition only
  26. };
  27. template<typename IteratorTuple>
  28. zip_iterator<IteratorTuple>
  29. make_zip_iterator(IteratorTuple t);
  30. The ``reference`` member of ``zip_iterator`` is the type of the tuple
  31. made of the reference types of the iterator types in the ``IteratorTuple``
  32. argument.
  33. The ``difference_type`` member of ``zip_iterator`` is the ``difference_type``
  34. of the first of the iterator types in the ``IteratorTuple`` argument.
  35. The ``iterator_category`` member of ``zip_iterator`` is convertible to the
  36. minimum of the traversal categories of the iterator types in the ``IteratorTuple``
  37. argument. For example, if the ``zip_iterator`` holds only vector
  38. iterators, then ``iterator_category`` is convertible to
  39. ``boost::random_access_traversal_tag``. If you add a list iterator, then
  40. ``iterator_category`` will be convertible to ``boost::bidirectional_traversal_tag``,
  41. but no longer to ``boost::random_access_traversal_tag``.
  42. ``zip_iterator`` requirements
  43. ...................................
  44. All iterator types in the argument ``IteratorTuple`` shall model Readable Iterator.
  45. ``zip_iterator`` models
  46. .............................
  47. The resulting ``zip_iterator`` models Readable Iterator.
  48. The fact that the ``zip_iterator`` models only Readable Iterator does not
  49. prevent you from modifying the values that the individual iterators point
  50. to. The tuple returned by the ``zip_iterator``'s ``operator*`` is a tuple
  51. constructed from the reference types of the individual iterators, not
  52. their value types. For example, if ``zip_it`` is a ``zip_iterator`` whose
  53. first member iterator is an ``std::vector<double>::iterator``, then the
  54. following line will modify the value which the first member iterator of
  55. ``zip_it`` currently points to:
  56. ::
  57. zip_it->get<0>() = 42.0;
  58. Consider the set of standard traversal concepts obtained by taking
  59. the most refined standard traversal concept modeled by each individual
  60. iterator type in the ``IteratorTuple`` argument.The ``zip_iterator``
  61. models the least refined standard traversal concept in this set.
  62. ``zip_iterator<IteratorTuple1>`` is interoperable with
  63. ``zip_iterator<IteratorTuple2>`` if and only if ``IteratorTuple1``
  64. is interoperable with ``IteratorTuple2``.
  65. ``zip_iterator`` operations
  66. .................................
  67. In addition to the operations required by the concepts modeled by
  68. ``zip_iterator``, ``zip_iterator`` provides the following
  69. operations.
  70. ``zip_iterator();``
  71. :Returns: An instance of ``zip_iterator`` with ``m_iterator_tuple``
  72. default constructed.
  73. ``zip_iterator(IteratorTuple iterator_tuple);``
  74. :Returns: An instance of ``zip_iterator`` with ``m_iterator_tuple``
  75. initialized to ``iterator_tuple``.
  76. ::
  77. template<typename OtherIteratorTuple>
  78. zip_iterator(
  79. const zip_iterator<OtherIteratorTuple>& other
  80. , typename enable_if_convertible<
  81. OtherIteratorTuple
  82. , IteratorTuple>::type* = 0 // exposition only
  83. );
  84. :Returns: An instance of ``zip_iterator`` that is a copy of ``other``.
  85. :Requires: ``OtherIteratorTuple`` is implicitly convertible to ``IteratorTuple``.
  86. ``const IteratorTuple& get_iterator_tuple() const;``
  87. :Returns: ``m_iterator_tuple``
  88. ``reference operator*() const;``
  89. :Returns: A tuple consisting of the results of dereferencing all iterators in
  90. ``m_iterator_tuple``.
  91. ``zip_iterator& operator++();``
  92. :Effects: Increments each iterator in ``m_iterator_tuple``.
  93. :Returns: ``*this``
  94. ``zip_iterator& operator--();``
  95. :Effects: Decrements each iterator in ``m_iterator_tuple``.
  96. :Returns: ``*this``
  97. ::
  98. template<typename IteratorTuple>
  99. zip_iterator<IteratorTuple>
  100. make_zip_iterator(IteratorTuple t);
  101. :Returns: An instance of ``zip_iterator<IteratorTuple>`` with ``m_iterator_tuple``
  102. initialized to ``t``.