title: Expose a vector as a memoryview using SWIG
body: <p>I have a header file like:</p>
  
  <pre><code>#include &lt;vector&gt;
  
  inline std::vector&lt;uint8_t&gt;&amp; vec() {
    static std::vector&lt;uint8_t&gt; v { 'a', 'b', 'c', 'd' };
    return v;
  }
  
  inline const std::vector&lt;uint8_t&gt;&amp; cvec() {
    return vec();
  }
  </code></pre>
  
  <p>I can <a href="https://stackoverflow.com/questions/8896828/make-c-array-of-objects-iterable-in-python/8898129#8898129">wrap it in SWIG using std_vector.i and pyabc.i</a> but that is quite inefficient (there's a jump between C++ and Python code for every access) and given that these are literally just a bunch of bytes I ought to be able to wrap them with <a href="http://docs.python.org/2/library/stdtypes.html#memoryview" rel="nofollow noreferrer">Python's <code>memoryview</code> interface</a>.</p>
  
  <p>How can I expose my <code>std::vector&lt;uint8_t&gt;</code> as a Python <code>memoryview</code>?</p>