title: Generic iterator
body: <p>I am trying to find a generic way of accessing a set of containers. I have a standard vector and list in addition to another custom list.</p>
  
  <p>The custom list defines an iterator;</p>
  
  <pre><code>class Iterator: public std::iterator&lt;std::forward_iterator_tag, T&gt; {
      // ...
  }
  
  Iterator begin() {
      return (Iterator(root));
  }
  
  Iterator end() {
      return (Iterator(NULL));
  }
  </code></pre>
  
  <p>with the appropriate operators overloaded. </p>
  
  <p>Ideally, I would like to do this;</p>
  
  <pre><code>class Foo {
  public:
      Foo() {
          std::list&lt;int&gt; x;
          std::vector&lt;int&gt; y;
          custom_list&lt;int&gt; z;
  
          iter = x.begin(); // OR
          iter = y.begin(); // OR
          iter = z.begin();
  
          // ...
      };
  private:
      std::iterator&lt;int&gt; iter;
  };
  </code></pre>
  
  <p>But obviously these are all iterators of different types. I can assume all the containers are of the same type however.</p>
  
  <p>Is there an elegant way to solve this problem?</p>