archetypes.qbk 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. [section:archetypes Iterator Archetypes]
  2. The `iterator_archetype` class constructs a minimal implementation of
  3. one of the iterator access concepts and one of the iterator traversal concepts.
  4. This is used for doing a compile-time check to see if a the type requirements
  5. of a template are really enough to cover the implementation of the template.
  6. For further information see the documentation for the |concepts|_ library.
  7. [h2 Synopsis]
  8. namespace iterator_archetypes
  9. {
  10. // Access categories
  11. typedef /*implementation defined*/ readable_iterator_t;
  12. typedef /*implementation defined*/ writable_iterator_t;
  13. typedef /*implementation defined*/ readable_writable_iterator_t;
  14. typedef /*implementation defined*/ readable_lvalue_iterator_t;
  15. typedef /*implementation defined*/ writable_lvalue_iterator_t;
  16. }
  17. template <
  18. class Value
  19. , class AccessCategory
  20. , class TraversalCategory
  21. >
  22. class iterator_archetype
  23. {
  24. typedef /* see below */ value_type;
  25. typedef /* see below */ reference;
  26. typedef /* see below */ pointer;
  27. typedef /* see below */ difference_type;
  28. typedef /* see below */ iterator_category;
  29. };
  30. [h3 Access Category Tags]
  31. The access category types provided correspond to the following
  32. standard iterator access concept combinations:
  33. readable_iterator_t :=
  34. Readable Iterator
  35. writable_iterator_t :=
  36. Writeable Iterator
  37. readable_writable_iterator_t :=
  38. Readable Iterator & Writeable Iterator & Swappable Iterator
  39. readable_lvalue_iterator_t :=
  40. Readable Iterator & Lvalue Iterator
  41. writeable_lvalue_iterator_t :=
  42. Readable Iterator & Writeable Iterator & Swappable Iterator & Lvalue Iterator
  43. [h3 Traits]
  44. The nested trait types are defined as follows:
  45. if (AccessCategory == readable_iterator_t)
  46. value_type = Value
  47. reference = Value
  48. pointer = Value*
  49. else if (AccessCategory == writable_iterator_t)
  50. value_type = void
  51. reference = void
  52. pointer = void
  53. else if (AccessCategory == readable_writable_iterator_t)
  54. value_type = Value
  55. reference :=
  56. A type X that is convertible to Value for which the following
  57. expression is valid. Given an object x of type X and v of type
  58. Value.
  59. x = v
  60. pointer = Value*
  61. else if (AccessCategory == readable_lvalue_iterator_t)
  62. value_type = Value
  63. reference = Value const&
  64. pointer = Value const*
  65. else if (AccessCategory == writable_lvalue_iterator_t)
  66. value_type = Value
  67. reference = Value&
  68. pointer = Value*
  69. if ( TraversalCategory is convertible to forward_traversal_tag )
  70. difference_type := ptrdiff_t
  71. else
  72. difference_type := unspecified type
  73. iterator_category :=
  74. A type X satisfying the following two constraints:
  75. 1. X is convertible to X1, and not to any more-derived
  76. type, where X1 is defined by:
  77. if (reference is a reference type
  78. && TraversalCategory is convertible to forward_traversal_tag)
  79. {
  80. if (TraversalCategory is convertible to random_access_traversal_tag)
  81. X1 = random_access_iterator_tag
  82. else if (TraversalCategory is convertible to bidirectional_traversal_tag)
  83. X1 = bidirectional_iterator_tag
  84. else
  85. X1 = forward_iterator_tag
  86. }
  87. else
  88. {
  89. if (TraversalCategory is convertible to single_pass_traversal_tag
  90. && reference != void)
  91. X1 = input_iterator_tag
  92. else
  93. X1 = output_iterator_tag
  94. }
  95. 2. X is convertible to TraversalCategory
  96. [h2 Requirements]
  97. The `AccessCategory` argument must be one of the predefined access
  98. category tags. The `TraversalCategory` must be one of the standard
  99. traversal tags. The `Value` type must satisfy the requirements of
  100. the iterator concept specified by `AccessCategory` and
  101. `TraversalCategory` as implied by the nested traits types.
  102. [h2 Concepts]
  103. `iterator_archetype` models the iterator concepts specified by the
  104. `AccessCategory` and `TraversalCategory`
  105. arguments. `iterator_archetype` does not model any other access
  106. concepts or any more derived traversal concepts.
  107. [endsect]