1 / 5

Iterators

Iterators. A pure abstraction. Introduction. “Iterators are the glue that holds containers and algorithms togther”. P 549 The C++ Programming Language, Bjarne Stroustrup They provide an abstract view of data Iterators support an abstract model of data as sequences. Iterators and Sequences.

nara
Download Presentation

Iterators

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Iterators A pure abstraction

  2. Introduction • “Iterators are the glue that holds containers and algorithms togther”. • P 549 The C++ Programming Language, Bjarne Stroustrup • They provide an abstract view of data • Iterators support an abstract model of data as sequences.

  3. Iterators and Sequences • An iterator is pure abstraction • Anything that behaves like an iterator is an iterator • An iterator is an abstraction of a pointer to an element of a sequence • For example, an int* is an interator to int[]

  4. More Iterator Issues • There is no concept of a “null iterator” • An iterator that points to nothing typically points to the same value as “one past the end” and should be compared to that same value • If an iterator points to an element, it is said to be valid.

  5. Const Iterators • Const iterators support the same behavior as non-const interators with the major exception that const iterators are not allow to modify the container to which they point.

More Related