@@ -139,54 +139,58 @@ class List {
139
139
140
140
typedef T ValueType;
141
141
142
- struct Iterator {
143
- _FORCE_INLINE_ T &operator *() const {
142
+ struct ConstIterator {
143
+ _FORCE_INLINE_ const T &operator *() const {
144
144
return E->get ();
145
145
}
146
- _FORCE_INLINE_ T *operator ->() const { return &E->get (); }
147
- _FORCE_INLINE_ Iterator &operator ++() {
146
+ _FORCE_INLINE_ const T *operator ->() const { return &E->get (); }
147
+ _FORCE_INLINE_ ConstIterator &operator ++() {
148
148
E = E->next ();
149
149
return *this ;
150
150
}
151
- _FORCE_INLINE_ Iterator &operator --() {
151
+ _FORCE_INLINE_ ConstIterator &operator --() {
152
152
E = E->prev ();
153
153
return *this ;
154
154
}
155
155
156
- _FORCE_INLINE_ bool operator ==(const Iterator &b) const { return E == b.E ; }
157
- _FORCE_INLINE_ bool operator !=(const Iterator &b) const { return E != b.E ; }
156
+ _FORCE_INLINE_ bool operator ==(const ConstIterator &b) const { return E == b.E ; }
157
+ _FORCE_INLINE_ bool operator !=(const ConstIterator &b) const { return E != b.E ; }
158
158
159
- Iterator ( Element *p_E) { E = p_E; }
160
- Iterator () {}
161
- Iterator (const Iterator &p_it) { E = p_it.E ; }
159
+ _FORCE_INLINE_ ConstIterator ( const Element *p_E) { E = p_E; }
160
+ _FORCE_INLINE_ ConstIterator () {}
161
+ _FORCE_INLINE_ ConstIterator (const ConstIterator &p_it) { E = p_it.E ; }
162
162
163
163
private:
164
- Element *E = nullptr ;
164
+ const Element *E = nullptr ;
165
165
};
166
166
167
- struct ConstIterator {
168
- _FORCE_INLINE_ const T &operator *() const {
167
+ struct Iterator {
168
+ _FORCE_INLINE_ T &operator *() const {
169
169
return E->get ();
170
170
}
171
- _FORCE_INLINE_ const T *operator ->() const { return &E->get (); }
172
- _FORCE_INLINE_ ConstIterator &operator ++() {
171
+ _FORCE_INLINE_ T *operator ->() const { return &E->get (); }
172
+ _FORCE_INLINE_ Iterator &operator ++() {
173
173
E = E->next ();
174
174
return *this ;
175
175
}
176
- _FORCE_INLINE_ ConstIterator &operator --() {
176
+ _FORCE_INLINE_ Iterator &operator --() {
177
177
E = E->prev ();
178
178
return *this ;
179
179
}
180
180
181
- _FORCE_INLINE_ bool operator ==(const ConstIterator &b) const { return E == b.E ; }
182
- _FORCE_INLINE_ bool operator !=(const ConstIterator &b) const { return E != b.E ; }
181
+ _FORCE_INLINE_ bool operator ==(const Iterator &b) const { return E == b.E ; }
182
+ _FORCE_INLINE_ bool operator !=(const Iterator &b) const { return E != b.E ; }
183
183
184
- _FORCE_INLINE_ ConstIterator (const Element *p_E) { E = p_E; }
185
- _FORCE_INLINE_ ConstIterator () {}
186
- _FORCE_INLINE_ ConstIterator (const ConstIterator &p_it) { E = p_it.E ; }
184
+ Iterator (Element *p_E) { E = p_E; }
185
+ Iterator () {}
186
+ Iterator (const Iterator &p_it) { E = p_it.E ; }
187
+
188
+ operator ConstIterator () const {
189
+ return ConstIterator (E);
190
+ }
187
191
188
192
private:
189
- const Element *E = nullptr ;
193
+ Element *E = nullptr ;
190
194
};
191
195
192
196
_FORCE_INLINE_ Iterator begin () {
@@ -519,7 +523,14 @@ class List {
519
523
}
520
524
}
521
525
522
- T &operator [](int p_index) {
526
+ // Index operator, kept for compatibility.
527
+ _FORCE_INLINE_ T &operator [](int p_index) {
528
+ return get (p_index);
529
+ }
530
+
531
+ // Random access to elements, use with care,
532
+ // do not use for iteration.
533
+ T &get (int p_index) {
523
534
CRASH_BAD_INDEX (p_index, size ());
524
535
525
536
Element *I = front ();
@@ -532,7 +543,14 @@ class List {
532
543
return I->get ();
533
544
}
534
545
535
- const T &operator [](int p_index) const {
546
+ // Index operator, kept for compatibility.
547
+ _FORCE_INLINE_ const T &operator [](int p_index) const {
548
+ return get (p_index);
549
+ }
550
+
551
+ // Random access to elements, use with care,
552
+ // do not use for iteration.
553
+ const T &get (int p_index) const {
536
554
CRASH_BAD_INDEX (p_index, size ());
537
555
538
556
const Element *I = front ();
0 commit comments