comparison gen/utils.h @ 1262:ec1d9dc1d32a

Fixed struct default initializers.
author Tomas Lindquist Olsen <tomas.l.olsen gmail com>
date Sat, 25 Apr 2009 18:26:54 +0200
parents 79758fd2f48a
children
comparison
equal deleted inserted replaced
1257:7af860e4f403 1262:ec1d9dc1d32a
5 5
6 /// Very simple templated iterator for DMD ArrayS. 6 /// Very simple templated iterator for DMD ArrayS.
7 template<class C> 7 template<class C>
8 struct ArrayIter 8 struct ArrayIter
9 { 9 {
10 Array& array; 10 Array* array;
11 size_t index; 11 size_t index;
12 12
13 ArrayIter(Array& arr, size_t idx = 0) 13 ArrayIter(Array& arr, size_t idx = 0)
14 : array(&arr), index(idx)
15 { }
16 ArrayIter(Array* arr, size_t idx = 0)
14 : array(arr), index(idx) 17 : array(arr), index(idx)
15 { } 18 { assert(arr && "null array"); }
19
20 ArrayIter<C>& operator=(const Array& arr)
21 {
22 array = &arr;
23 index = 0;
24 return *this;
25 }
26 ArrayIter<C>& operator=(const Array* arr)
27 {
28 assert(arr && "null array");
29 array = arr;
30 index = 0;
31 return *this;
32 }
16 33
17 bool done() 34 bool done()
18 { 35 {
19 return index >= array.dim; 36 return index >= array->dim;
20 } 37 }
21 bool more() 38 bool more()
22 { 39 {
23 return index < array.dim; 40 return index < array->dim;
24 } 41 }
25 42
26 C* get() 43 C* get() {
27 { 44 return static_cast<C*>(array->data[index]);
28 return static_cast<C*>(array.data[index]);
29 } 45 }
30 C* operator->() 46 C* operator->() {
31 { 47 return get();
32 return static_cast<C*>(array.data[index]); 48 }
49 C* operator*() {
50 return get();
33 } 51 }
34 52
35 void next() 53 void next()
36 { 54 {
37 ++index; 55 ++index;
56 }
57
58 bool operator==(const ArrayIter<C>& other) {
59 return &array->data[index] == &other.array->data[other.index];
38 } 60 }
39 }; 61 };
40 62
41 // some aliases 63 // some aliases
42 typedef ArrayIter<Dsymbol> DsymbolIter; 64 typedef ArrayIter<Dsymbol> DsymbolIter;