From Jason Turner

[std.iterator.tags]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2i1x8oxk/{from.md → to.md} +11 -19
tmp/tmp2i1x8oxk/{from.md → to.md} RENAMED
@@ -19,26 +19,29 @@ namespace std {
19
  struct bidirectional_iterator_tag: public forward_iterator_tag { };
20
  struct random_access_iterator_tag: public bidirectional_iterator_tag { };
21
  }
22
  ```
23
 
 
 
24
  For a program-defined iterator `BinaryTreeIterator`, it could be
25
  included into the bidirectional iterator category by specializing the
26
  `iterator_traits` template:
27
 
28
  ``` cpp
29
  template<class T> struct iterator_traits<BinaryTreeIterator<T>> {
30
- typedef std::ptrdiff_t difference_type;
31
- typedef T value_type;
32
- typedef T* pointer;
33
- typedef T& reference;
34
- typedef bidirectional_iterator_tag iterator_category;
35
  };
36
  ```
37
 
38
- Typically, however, it would be easier to derive `BinaryTreeIterator<T>`
39
- from `iterator<bidirectional_iterator_tag,T,ptrdiff_t,T*,T&>`.
 
40
 
41
  If `evolve()` is well defined for bidirectional iterators, but can be
42
  implemented more efficiently for random access iterators, then the
43
  implementation is as follows:
44
 
@@ -61,18 +64,7 @@ void evolve(RandomAccessIterator first, RandomAccessIterator last,
61
  random_access_iterator_tag) {
62
  // more efficient, but less generic algorithm
63
  }
64
  ```
65
 
66
- If a C++program wants to define a bidirectional iterator for some data
67
- structure containing `double` and such that it works on a large memory
68
- model of the implementation, it can do so with:
69
-
70
- ``` cpp
71
- class MyIterator :
72
- public iterator<bidirectional_iterator_tag, double, long, T*, T&> {
73
- // code implementing ++, etc.
74
- };
75
- ```
76
-
77
- Then there is no need to specialize the `iterator_traits` template.
78
 
 
19
  struct bidirectional_iterator_tag: public forward_iterator_tag { };
20
  struct random_access_iterator_tag: public bidirectional_iterator_tag { };
21
  }
22
  ```
23
 
24
+ [*Example 1*:
25
+
26
  For a program-defined iterator `BinaryTreeIterator`, it could be
27
  included into the bidirectional iterator category by specializing the
28
  `iterator_traits` template:
29
 
30
  ``` cpp
31
  template<class T> struct iterator_traits<BinaryTreeIterator<T>> {
32
+ using iterator_category = bidirectional_iterator_tag;
33
+ using difference_type = ptrdiff_t;
34
+ using value_type = T;
35
+ using pointer = T*;
36
+ using reference = T&;
37
  };
38
  ```
39
 
40
+ *end example*]
41
+
42
+ [*Example 2*:
43
 
44
  If `evolve()` is well defined for bidirectional iterators, but can be
45
  implemented more efficiently for random access iterators, then the
46
  implementation is as follows:
47
 
 
64
  random_access_iterator_tag) {
65
  // more efficient, but less generic algorithm
66
  }
67
  ```
68
 
69
+ *end example*]
 
 
 
 
 
 
 
 
 
 
 
70