title: Cursor vs Iterator pattern
body: <p>In numerous texts, I've seen the term cursor used interchangeably with the term iterator. However, it doesn't seem right that they are treated as the same thing.</p>
  
  <p>To me, an iterator allows iteration of a container with no knowledge of the container itself. A cursor, on the other hand, allows iteration of a container as well but has implementation details specific to the container type, so it does keep a reference to the container. Additionally a cursor's interface mirrors the interface of the container kind of like the facade pattern.</p>
  
  <p>Here is an example of what I would consider a cursor:</p>
  
  <pre><code>class Book {};
  
  class Library
  {
      std::vector&lt;Book&gt; books;
  
      bool IsBookHardCover( int bookIndex );
      bool IsBookSoftCover( int bookIndex );
  
      BookCursor GetFirstBook();
  };
  
  class BookCursor
  {
      std::vector&lt;Book&gt;&amp; books;
      int currentBook;
  
      bool IsHardCover();
      bool IsSoftCover();
  
      void Next();
  };
  </code></pre>
  
  <p>So basically I make the distinction between iterators and cursors based on their dependency or knowledge of the container they iterate. Is this an appropriate distinction? If not, what would you consider the design pattern I've outlined in my code example above?</p>
  
  <p>Note that my code example above should be treated as pseudocode since I did not compile it and it also lacks the constructors required.</p>