aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/array.h36
-rw-r--r--src/unit/array.unit2
2 files changed, 34 insertions, 4 deletions
diff --git a/src/array.h b/src/array.h
index e717fd5..ca4ec21 100644
--- a/src/array.h
+++ b/src/array.h
@@ -245,14 +245,19 @@ namespace Bu
245 return src[iPos]; 245 return src[iPos];
246 } 246 }
247 247
248 long getIndex() const
249 {
250 return iPos;
251 }
252
248 operator bool() const 253 operator bool() const
249 { 254 {
250 return iPos < 0; 255 return iPos >= 0;
251 } 256 }
252 257
253 bool isValid() const 258 bool isValid() const
254 { 259 {
255 return iPos < 0; 260 return iPos >= 0;
256 } 261 }
257 } iterator; 262 } iterator;
258 263
@@ -337,15 +342,20 @@ namespace Bu
337 "Cannot dereference finished iterator."); 342 "Cannot dereference finished iterator.");
338 return src[iPos]; 343 return src[iPos];
339 } 344 }
345
346 long getIndex() const
347 {
348 return iPos;
349 }
340 350
341 operator bool() const 351 operator bool() const
342 { 352 {
343 return iPos < 0; 353 return iPos >= 0;
344 } 354 }
345 355
346 bool isValid() const 356 bool isValid() const
347 { 357 {
348 return iPos < 0; 358 return iPos >= 0;
349 } 359 }
350 } const_iterator; 360 } const_iterator;
351 361
@@ -414,6 +424,24 @@ namespace Bu
414 long iSize; 424 long iSize;
415 long iCapacity; 425 long iCapacity;
416 }; 426 };
427
428 class Formatter;
429 Formatter &operator<<( Formatter &rOut, char *sStr );
430 Formatter &operator<<( Formatter &rOut, signed char c );
431 template<typename value>
432 Formatter &operator<<( Formatter &f, const Bu::Array<value> &a )
433 {
434 f << '[';
435 for( typename Bu::Array<value>::const_iterator i = a.begin(); i; i++ )
436 {
437 if( i != a.begin() )
438 f << ", ";
439 f << *i;
440 }
441 f << ']';
442
443 return f;
444 }
417} 445}
418 446
419#endif 447#endif
diff --git a/src/unit/array.unit b/src/unit/array.unit
index d5fc573..3a777d3 100644
--- a/src/unit/array.unit
+++ b/src/unit/array.unit
@@ -32,11 +32,13 @@
32 int j = 0; 32 int j = 0;
33 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) 33 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
34 unitTest( (*i) == j++ ); 34 unitTest( (*i) == j++ );
35 unitTest( j == 10 );
35 36
36 const Bu::Array<int> &ci = ai; 37 const Bu::Array<int> &ci = ai;
37 j = 0; 38 j = 0;
38 for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ ) 39 for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ )
39 unitTest( (*i) == j++ ); 40 unitTest( (*i) == j++ );
41 unitTest( j == 10 );
40} 42}
41 43
42{%iterate2} 44{%iterate2}