diff options
Diffstat (limited to 'src/list.h')
-rw-r--r-- | src/list.h | 26 |
1 files changed, 22 insertions, 4 deletions
@@ -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 | ||