title: How to implement a slice operator[] in C++?
body: <p>This is probably a duplicate question but I can't seem to find the answer... I'm trying to implement a slicable container like object in C++ using the <code>operator[]</code>. Here's my implementation (which doesn't work):</p>
  
  <pre><code>class SlicableIntVector{
  private:
      std::vector&lt;int&gt; vector;
  public:
      explicit SlicableIntVector(std::vector&lt;int&gt; vector): vector(vector){};
  
      // The usual way of overloading operator[]
      int &amp;operator[](int index){
          return vector[index];
      }
      // This version doesn't work as the argument is not binary
      int &amp;operator[](int start, int end){
          return vector[vector.begin()+start, vector.begin()+start+end];
      }
  
      }
  };
  </code></pre>
  
  <p>Other than just using another method to implement the slicing operation, what options do I have to get slicing working with <code>operator[]</code>? If I could get the flexibility of slicing like a python <code>list</code> I'd be happy. </p>