1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | |
6 | |
7 | #pragma once |
8 | |
9 | namespace jitstd |
10 | { |
11 | |
12 | template <class Category, class T, class Distance = ptrdiff_t, class Pointer = T*, class Reference = T&> |
13 | struct iterator |
14 | { |
15 | typedef T value_type; |
16 | typedef Distance difference_type; |
17 | typedef Pointer pointer; |
18 | typedef Reference reference; |
19 | typedef Category iterator_category; |
20 | }; |
21 | |
22 | struct input_iterator_tag |
23 | { |
24 | }; |
25 | |
26 | struct forward_iterator_tag : public input_iterator_tag |
27 | { |
28 | }; |
29 | |
30 | struct bidirectional_iterator_tag : public forward_iterator_tag |
31 | { |
32 | }; |
33 | |
34 | struct random_access_iterator_tag : public bidirectional_iterator_tag |
35 | { |
36 | }; |
37 | |
38 | struct int_not_an_iterator_tag |
39 | { |
40 | }; |
41 | |
42 | template <typename Iterator> |
43 | struct iterator_traits |
44 | { |
45 | typedef typename Iterator::difference_type difference_type; |
46 | typedef typename Iterator::value_type value_type; |
47 | typedef typename Iterator::pointer pointer; |
48 | typedef typename Iterator::reference reference; |
49 | typedef typename Iterator::iterator_category iterator_category; |
50 | }; |
51 | |
52 | template <typename T> |
53 | struct iterator_traits<T*> |
54 | { |
55 | typedef ptrdiff_t difference_type; |
56 | typedef T value_type; |
57 | typedef T* pointer; |
58 | typedef T& reference; |
59 | typedef random_access_iterator_tag iterator_category; |
60 | }; |
61 | |
62 | template <typename T> |
63 | struct iterator_traits<const T*> |
64 | { |
65 | typedef ptrdiff_t difference_type; |
66 | typedef T value_type; |
67 | typedef const T* pointer; |
68 | typedef const T& reference; |
69 | typedef random_access_iterator_tag iterator_category; |
70 | }; |
71 | |
72 | template<> |
73 | struct iterator_traits<bool> |
74 | { |
75 | typedef int_not_an_iterator_tag iterator_category; |
76 | }; |
77 | |
78 | template<> |
79 | struct iterator_traits<char> |
80 | { |
81 | typedef int_not_an_iterator_tag iterator_category; |
82 | }; |
83 | |
84 | template<> |
85 | struct iterator_traits<signed char> |
86 | { |
87 | typedef int_not_an_iterator_tag iterator_category; |
88 | }; |
89 | |
90 | template<> |
91 | struct iterator_traits<unsigned char> |
92 | { |
93 | typedef int_not_an_iterator_tag iterator_category; |
94 | }; |
95 | |
96 | template<> |
97 | struct iterator_traits<short> |
98 | { |
99 | typedef int_not_an_iterator_tag iterator_category; |
100 | }; |
101 | |
102 | template<> |
103 | struct iterator_traits<unsigned short> |
104 | { |
105 | typedef int_not_an_iterator_tag iterator_category; |
106 | }; |
107 | |
108 | template<> |
109 | struct iterator_traits<int> |
110 | { |
111 | typedef int_not_an_iterator_tag iterator_category; |
112 | }; |
113 | |
114 | template<> |
115 | struct iterator_traits<unsigned int> |
116 | { |
117 | typedef int_not_an_iterator_tag iterator_category; |
118 | }; |
119 | |
120 | template<> |
121 | struct iterator_traits<__int64> |
122 | { |
123 | typedef int_not_an_iterator_tag iterator_category; |
124 | }; |
125 | |
126 | template<> |
127 | struct iterator_traits<unsigned __int64> |
128 | { |
129 | typedef int_not_an_iterator_tag iterator_category; |
130 | }; |
131 | |
132 | namespace util |
133 | { |
134 | template<class Iterator> |
135 | inline |
136 | typename iterator_traits<Iterator>::iterator_category |
137 | iterator_category(const Iterator&) |
138 | { |
139 | typename iterator_traits<Iterator>::iterator_category categ; |
140 | return categ; |
141 | } |
142 | } // end of namespace util. |
143 | |
144 | } // end of namespace jitstd. |
145 | |