title: construct a vector in range without copying
body: <p>I have a class that wraps a big array of bytes that are network packets. The class implements a queue and provides (among others) <code>front()</code> function that returns a const vector of bytes that constitute the oldest packet in the queue. </p>
  
  <pre><code>class Buffer{
    unsigned char data[65536];
    unsigned int offset;
    unsigned int length;
    [...]//other fields for maintaining write ptr etc.
  
  public:
    const std::vector&lt;unsigned char&gt; front(){
      return std::vector&lt;unsigned char&gt;(data + offset, data + offset + length);
    }
  
    //other methods for accessing the queue like
    //pop(), push(), clean() and so forth...
    [...]
  }
  </code></pre>
  
  <p>The performance of above implementation of <code>front()</code> function suffers from unnecessary copying bytes from the range occupied by the current packet. Since the vector is const, there is no need of making a copy of the data. What I want is to create a vector on the data that are already stored in the buffer. Of course destructor of the vector should not deallocate the memory.</p>