1
2
3
4
5
6 namespace System
7 {
8 public class RandomAccessIter<T, R, P>
9 {
10 public typedef T ValueType;
11 public typedef R ReferenceType;
12 public typedef P PointerType;
13 private typedef RandomAccessIter<ValueType, ReferenceType, PointerType> Self;
14
15 public inline RandomAccessIter() : ptr(null)
16 {
17 }
18 public inline explicit RandomAccessIter(PointerType ptr_) : ptr(ptr_)
19 {
20 }
21 public inline Self& operator++()
22 {
23 #assert(ptr != null);
24 ++ptr;
25 return *this;
26 }
27 public inline Self& operator--()
28 {
29 #assert(ptr != null);
30 --ptr;
31 return *this;
32 }
33 public inline ReferenceType operator*()
34 {
35 #assert(ptr != null);
36 return *ptr;
37 }
38 public inline PointerType operator->()
39 {
40 #assert(ptr != null);
41 return ptr;
42 }
43 public inline ReferenceType operator[](long index)
44 {
45 #assert(ptr != null);
46 return ptr[index];
47 }
48 public inline PointerType Ptr() const
49 {
50 return ptr;
51 }
52 private PointerType ptr;
53 }
54
55 public inline RandomAccessIter<T, R, P> operator+<T, R, P>(const RandomAccessIter<T, R, P>& it, long offset)
56 {
57 #assert(it.Ptr() != null);
58 return RandomAccessIter<T, R, P>(it.Ptr() + offset);
59 }
60
61 public inline RandomAccessIter<T, R, P> operator+<T, R, P>(long offset, const RandomAccessIter<T, R, P>& it)
62 {
63 #assert(it.Ptr() != null);
64 return RandomAccessIter<T, R, P>(it.Ptr() + offset);
65 }
66
67 public inline RandomAccessIter<T, R, P> operator-<T, R, P>(const RandomAccessIter<T, R, P>& it, long offset)
68 {
69 #assert(it.Ptr() != null);
70 return RandomAccessIter<T, R, P>(it.Ptr() - offset);
71 }
72
73 public inline long operator-<T, R, P>(const RandomAccessIter<T, R, P>& left, const RandomAccessIter<T, R, P>& right)
74 {
75 #assert((left.Ptr() == null && right.Ptr() == null || left.Ptr() != null && right.Ptr() != null));
76 if (left.Ptr() == null && right.Ptr() == null)
77 {
78 return 0;
79 }
80 return left.Ptr() - right.Ptr();
81 }
82
83 public inline bool operator==<T, R, P>(const RandomAccessIter<T, R, P>& left, const RandomAccessIter<T, R, P>& right)
84 {
85 return left.Ptr() == right.Ptr();
86 }
87
88 public inline bool operator<<T, R, P>(const RandomAccessIter<T, R, P>& left, const RandomAccessIter<T, R, P>& right)
89 {
90 #assert((left.Ptr() == null && right.Ptr() == null || left.Ptr() != null && right.Ptr() != null));
91 return left.Ptr() < right.Ptr();
92 }