iterator_archetypes.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 Archetype
  6. ++++++++++++++++++++
  7. :Author: David Abrahams, Jeremy Siek, Thomas Witt
  8. :Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com
  9. :organization: `Boost Consulting`_, Indiana University `Open Systems
  10. Lab`_, `Zephyr Associates, Inc.`_
  11. :date: $Date$
  12. :copyright: Copyright David Abrahams, Jeremy Siek, and Thomas Witt 2004.
  13. .. _`Boost Consulting`: http://www.boost-consulting.com
  14. .. _`Open Systems Lab`: http://www.osl.iu.edu
  15. .. _`Zephyr Associates, Inc.`: http://www.styleadvisor.com
  16. :abstract: The ``iterator_archetype`` class constructs a minimal implementation of
  17. one of the iterator access concepts and one of the iterator traversal concepts.
  18. This is used for doing a compile-time check to see if a the type requirements
  19. of a template are really enough to cover the implementation of the template.
  20. For further information see the documentation for the |concepts|_ library.
  21. .. |concepts| replace:: ``boost::concept_check``
  22. .. _concepts: ../../concept_check/index.html
  23. .. contents:: Table of Contents
  24. Reference
  25. =========
  26. ``iterator_archetype`` Synopsis
  27. ...............................
  28. ::
  29. namespace iterator_archetypes
  30. {
  31. // Access categories
  32. typedef /*implementation defined*/ readable_iterator_t;
  33. typedef /*implementation defined*/ writable_iterator_t;
  34. typedef /*implementation defined*/ readable_writable_iterator_t;
  35. typedef /*implementation defined*/ readable_lvalue_iterator_t;
  36. typedef /*implementation defined*/ writable_lvalue_iterator_t;
  37. }
  38. template <
  39. class Value
  40. , class AccessCategory
  41. , class TraversalCategory
  42. >
  43. class iterator_archetype
  44. {
  45. typedef /* see below */ value_type;
  46. typedef /* see below */ reference;
  47. typedef /* see below */ pointer;
  48. typedef /* see below */ difference_type;
  49. typedef /* see below */ iterator_category;
  50. };
  51. ``Access Category Tags``
  52. ........................
  53. The access category types provided correspond to the following
  54. standard iterator access concept combinations:
  55. ::
  56. readable_iterator_t :=
  57. Readable Iterator
  58. writable_iterator_t :=
  59. Writeable Iterator
  60. readable_writable_iterator_t :=
  61. Readable Iterator & Writeable Iterator & Swappable Iterator
  62. readable_lvalue_iterator_t :=
  63. Readable Iterator & Lvalue Iterator
  64. writeable_lvalue_iterator_t :=
  65. Readable Iterator & Writeable Iterator & Swappable Iterator & Lvalue Iterator
  66. ``iterator_archetype`` Requirements
  67. ...................................
  68. The ``AccessCategory`` argument must be one of the predefined access
  69. category tags. The ``TraversalCategory`` must be one of the standard
  70. traversal tags. The ``Value`` type must satisfy the requirements of
  71. the iterator concept specified by ``AccessCategory`` and
  72. ``TraversalCategory`` as implied by the nested traits types.
  73. ``iterator_archetype`` Models
  74. .............................
  75. ``iterator_archetype`` models the iterator concepts specified by the
  76. ``AccessCategory`` and ``TraversalCategory``
  77. arguments. ``iterator_archetype`` does not model any other access
  78. concepts or any more derived traversal concepts.
  79. ``Traits``
  80. ..........
  81. The nested trait types are defined as follows:
  82. ::
  83. if (AccessCategory == readable_iterator_t)
  84. value_type = Value
  85. reference = Value
  86. pointer = Value*
  87. else if (AccessCategory == writable_iterator_t)
  88. value_type = void
  89. reference = void
  90. pointer = void
  91. else if (AccessCategory == readable_writable_iterator_t)
  92. value_type = Value
  93. reference :=
  94. A type X that is convertible to Value for which the following
  95. expression is valid. Given an object x of type X and v of type
  96. Value.
  97. x = v
  98. pointer = Value*
  99. else if (AccessCategory == readable_lvalue_iterator_t)
  100. value_type = Value
  101. reference = Value const&
  102. pointer = Value const*
  103. else if (AccessCategory == writable_lvalue_iterator_t)
  104. value_type = Value
  105. reference = Value&
  106. pointer = Value*
  107. if ( TraversalCategory is convertible to forward_traversal_tag )
  108. difference_type := ptrdiff_t
  109. else
  110. difference_type := unspecified type
  111. iterator_category :=
  112. A type X satisfying the following two constraints:
  113. 1. X is convertible to X1, and not to any more-derived
  114. type, where X1 is defined by:
  115. if (reference is a reference type
  116. && TraversalCategory is convertible to forward_traversal_tag)
  117. {
  118. if (TraversalCategory is convertible to random_access_traversal_tag)
  119. X1 = random_access_iterator_tag
  120. else if (TraversalCategory is convertible to bidirectional_traversal_tag)
  121. X1 = bidirectional_iterator_tag
  122. else
  123. X1 = forward_iterator_tag
  124. }
  125. else
  126. {
  127. if (TraversalCategory is convertible to single_pass_traversal_tag
  128. && reference != void)
  129. X1 = input_iterator_tag
  130. else
  131. X1 = output_iterator_tag
  132. }
  133. 2. X is convertible to TraversalCategory