title: How to write a simple, type-erased composable iterator in C++11
body: <p>I'm trying to write a simple composable Iterator that does not expose the internal type (so I can use one of these iterators in the interface and can realize different operations like concat, filter, ...). It's really intended to be simple but I'm currently stumbling over a simple compile error which I can't resolve</p>
  
  <pre><code>#define CATCH_CONFIG_MAIN
  #include "catch.hpp"
  
  #include &lt;functional&gt;
  #include &lt;vector&gt;
  
  template &lt;typename T&gt;
  struct RangeIteratorData
  {
      std::function&lt;T&amp;()&gt; dereference;
      std::function&lt;void()&gt; increment;
  };
  
  template &lt;typename T&gt;
  class RangeIterator
  {
  public:
      template &lt;typename I&gt;
      RangeIterator(I&amp; iter)
      {
          auto dereference = [iter]() { return *iter; };
          auto increment = [iter]() -&gt; void { ++iter; }; //here's the error
          m_data.dereference = dereference;
          m_data.increment = increment;
      }
  
      T&amp; operator*();
      RangeIterator&lt;T&gt;&amp; operator++();
  private:
      RangeIteratorData&lt;T&gt; m_data;
  };
  
  template &lt;typename T&gt;
  RangeIterator&lt;T&gt;&amp; RangeIterator&lt;T&gt;::operator++()
  {
      m_data.increment();
      return *this;
  }
  
  template &lt;typename T&gt;
  T&amp; RangeIterator&lt;T&gt;::operator*()
  {
      return m_data.dereference();;
  }
  
  TEST_CASE("Wrap existing iterator in range iterator")
  {
      std::vector&lt;int&gt; container{ 1,2,3 };
      RangeIterator&lt;int&gt; begin = RangeIterator&lt;int&gt;(container.begin());
      ++begin;
      REQUIRE(*begin == 1);
  }
  </code></pre>
  
  <p>The error message is:</p>
  
  <blockquote>
    <p>Error C2678   binary '++': no operator found which takes a left-hand operand of type 'const std::_Vector_iterator>>' (or there is no acceptable conversion)  </p>
  </blockquote>
  
  <p>I'm using VS2015. The code itself is far from complete but I don't get the meaning of this error message. I especially don't understand where the const comes from.</p>
  
  <p>It would be nice if someone could point me in the correct location.</p>