aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-07-06 22:51:19 +0000
committerMike Buland <eichlan@xagasoft.com>2007-07-06 22:51:19 +0000
commita7a5a9ee34ab34a2cfbf4048beb1f1d503fabd31 (patch)
tree2b99891995eae202a4ba9e0dd4bf7b44decbf2d8
parentc36256531396d75333669fafd5443c182bb0ab5e (diff)
downloadlibbu++-a7a5a9ee34ab34a2cfbf4048beb1f1d503fabd31.tar.gz
libbu++-a7a5a9ee34ab34a2cfbf4048beb1f1d503fabd31.tar.bz2
libbu++-a7a5a9ee34ab34a2cfbf4048beb1f1d503fabd31.tar.xz
libbu++-a7a5a9ee34ab34a2cfbf4048beb1f1d503fabd31.zip
Ok, some more fixes to the iterators in Bu::List
-rw-r--r--src/list.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/list.h b/src/list.h
index 3e5e292..2ac12e0 100644
--- a/src/list.h
+++ b/src/list.h
@@ -159,6 +159,11 @@ namespace Bu
159 } 159 }
160 160
161 public: 161 public:
162 iterator( const iterator &i ) :
163 pLink( i.pLink )
164 {
165 }
166
162 /** 167 /**
163 * Equals comparison operator. 168 * Equals comparison operator.
164 *@param oth (const iterator &) The iterator to compare to. 169 *@param oth (const iterator &) The iterator to compare to.
@@ -287,12 +292,12 @@ namespace Bu
287 { 292 {
288 } 293 }
289 294
295 public:
290 const_iterator( const iterator &i ) : 296 const_iterator( const iterator &i ) :
291 pLink( i.pLink ) 297 pLink( i.pLink )
292 { 298 {
293 } 299 }
294 300
295 public:
296 bool operator==( const const_iterator &oth ) const 301 bool operator==( const const_iterator &oth ) const
297 { 302 {
298 return ( pLink == oth.pLink ); 303 return ( pLink == oth.pLink );
@@ -393,7 +398,22 @@ namespace Bu
393 } 398 }
394 399
395 /** 400 /**
396 * Erase an item from the list. 401 * Erase an item from the list. After erasing the iterator will point
402 * to an invalid location and should be ignored. To erase an item from
403 * a list in a loop you should create a backup iterator.
404 *@code
405 for( List<>::iterator i = l.begin(); i != l.end(); i++ )
406 {
407 if( ...(needs delete)... )
408 {
409 List<>::iterator prev = i;
410 prev--;
411 l.erase( i );
412 i = prev;
413 continue;
414 }
415 }
416 @endcode
397 *@param i (iterator) The item to erase. 417 *@param i (iterator) The item to erase.
398 */ 418 */
399 void erase( iterator i ) 419 void erase( iterator i )
@@ -410,7 +430,6 @@ namespace Bu
410 if( pFirst == NULL ) 430 if( pFirst == NULL )
411 pLast = NULL; 431 pLast = NULL;
412 nSize--; 432 nSize--;
413 i.pLink = pFirst;
414 } 433 }
415 else 434 else
416 { 435 {
@@ -423,7 +442,6 @@ namespace Bu
423 if( pTmp != NULL ) 442 if( pTmp != NULL )
424 pTmp->pPrev = pPrev; 443 pTmp->pPrev = pPrev;
425 nSize--; 444 nSize--;
426 i.pLink = pTmp;
427 } 445 }
428 } 446 }
429 447