Pensar en C++ (Volumen 1) - Grupo ARCO
Pensar en C++ (Volumen 1) - Grupo ARCO Pensar en C++ (Volumen 1) - Grupo ARCO
✐ ✐ ✐ “Volumen1” — 2012/1/12 — 13:52 — page 510 — #548 ✐ Capítulo 16. Introducción a las Plantillas while(getline(file, line)) textlines.push(new string(line)); int i = 0; // Use iterator to print lines from the list: Stack::iterator it = textlines.begin(); Stack::iterator* it2 = 0; while(it != textlines.end()) { cout c_str()
✐ ✐ ✐ “Volumen1” — 2012/1/12 — 13:52 — page 511 — #549 ✐ 16.7. Introducción a los iteradores iterator(PStash& pStash) : ps(pStash), index(0) {} // To create the end sentinel: iterator(PStash& pStash, bool) : ps(pStash), index(ps.next) {} // Copy-constructor: iterator(const iterator& rv) : ps(rv.ps), index(rv.index) {} iterator& operator=(const iterator& rv) { ps = rv.ps; index = rv.index; return *this; } iterator& operator++() { require(++index = 0, "PStash::iterator::operator-- " "moves index out of bounds"); return *this; } iterator& operator--(int) { return operator--(); } // Jump interator forward or backward: iterator& operator+=(int amount) { require(index + amount < ps.next && index + amount >= 0, "PStash::iterator::operator+= " "attempt to index out of bounds"); index += amount; return *this; } iterator& operator-=(int amount) { require(index - amount < ps.next && index - amount >= 0, "PStash::iterator::operator-= " "attempt to index out of bounds"); index -= amount; return *this; } // Create a new iterator that’s moved forward iterator operator+(int amount) const { iterator ret(*this); ret += amount; // op+= does bounds check return ret; } T* current() const { return ps.storage[index]; } T* operator*() const { return current(); } 511 ✐ ✐ ✐ ✐
- Page 497 and 498: ✐ ✐ ✐ “Volumen1” — 2012
- Page 499 and 500: ✐ ✐ ✐ “Volumen1” — 2012
- Page 501 and 502: ✐ ✐ ✐ “Volumen1” — 2012
- Page 503 and 504: ✐ ✐ ✐ “Volumen1” — 2012
- Page 505 and 506: ✐ ✐ ✐ “Volumen1” — 2012
- Page 507 and 508: ✐ ✐ ✐ “Volumen1” — 2012
- Page 509 and 510: ✐ ✐ ✐ “Volumen1” — 2012
- Page 511 and 512: ✐ ✐ ✐ “Volumen1” — 2012
- Page 513 and 514: ✐ ✐ ✐ “Volumen1” — 2012
- Page 515 and 516: ✐ ✐ ✐ “Volumen1” — 2012
- Page 517 and 518: ✐ ✐ ✐ “Volumen1” — 2012
- Page 519 and 520: ✐ ✐ ✐ “Volumen1” — 2012
- Page 521 and 522: ✐ ✐ ✐ “Volumen1” — 2012
- Page 523 and 524: ✐ ✐ ✐ “Volumen1” — 2012
- Page 525 and 526: ✐ ✐ ✐ “Volumen1” — 2012
- Page 527 and 528: ✐ ✐ ✐ “Volumen1” — 2012
- Page 529 and 530: ✐ ✐ ✐ “Volumen1” — 2012
- Page 531 and 532: ✐ ✐ ✐ “Volumen1” — 2012
- Page 533 and 534: ✐ ✐ ✐ “Volumen1” — 2012
- Page 535 and 536: ✐ ✐ ✐ “Volumen1” — 2012
- Page 537 and 538: ✐ ✐ ✐ “Volumen1” — 2012
- Page 539 and 540: ✐ ✐ ✐ “Volumen1” — 2012
- Page 541 and 542: ✐ ✐ ✐ “Volumen1” — 2012
- Page 543 and 544: ✐ ✐ ✐ “Volumen1” — 2012
- Page 545 and 546: ✐ ✐ ✐ “Volumen1” — 2012
- Page 547: ✐ ✐ ✐ “Volumen1” — 2012
- Page 551 and 552: ✐ ✐ ✐ “Volumen1” — 2012
- Page 553 and 554: ✐ ✐ ✐ “Volumen1” — 2012
- Page 555 and 556: ✐ ✐ ✐ “Volumen1” — 2012
- Page 557 and 558: ✐ ✐ ✐ “Volumen1” — 2012
- Page 559 and 560: ✐ ✐ ✐ “Volumen1” — 2012
- Page 561 and 562: ✐ ✐ ✐ “Volumen1” — 2012
- Page 563 and 564: ✐ ✐ ✐ “Volumen1” — 2012
- Page 565 and 566: ✐ ✐ ✐ “Volumen1” — 2012
- Page 567 and 568: ✐ ✐ ✐ “Volumen1” — 2012
- Page 569 and 570: ✐ ✐ ✐ “Volumen1” — 2012
- Page 571 and 572: ✐ ✐ ✐ “Volumen1” — 2012
- Page 573 and 574: ✐ ✐ ✐ “Volumen1” — 2012
- Page 575 and 576: ✐ ✐ ✐ “Volumen1” — 2012
- Page 577 and 578: ✐ ✐ ✐ “Volumen1” — 2012
- Page 579 and 580: ✐ ✐ ✐ “Volumen1” — 2012
- Page 581 and 582: ✐ ✐ ✐ “Volumen1” — 2012
✐<br />
✐<br />
✐<br />
“Volum<strong>en</strong>1” — 2012/1/12 — 13:52 — page 510 — #548<br />
✐<br />
Capítulo 16. Introducción a las Plantillas<br />
while(getline(file, line))<br />
textlines.push(new string(line));<br />
int i = 0;<br />
// Use iterator to print lines from the list:<br />
Stack::iterator it = textlines.begin();<br />
Stack::iterator* it2 = 0;<br />
while(it != textlines.<strong>en</strong>d()) {<br />
cout c_str()