title: Exposing a C-style array data member to Python via Boost.Python
body: <p>I have a <code>struct</code> that contains a C-style array data member. I'd like to have this struct exposed to Python, and this data member be accessible as a list in Python. </p>
  
  <pre class="lang-cpp prettyprint-override"><code>struct S
  {
    char arr[4128];
  };
  
  void foo( S const * )
  {}
  
  BOOST_PYTHON_MODULE( test )
  {
    using namespace boost::python;
  
    class_&lt;S&gt;( "S" )
      .def_readwrite( "arr", &amp;S::arr )
      ;
  
    def( "foo", foo );
  }
  </code></pre>
  
  <p>The code above fails to build</p>
  
  <pre><code>error C2440: '=' : cannot convert from 'const char [4128]' to 'char [4128]'
  </code></pre>
  
  <p>C-style arrays are not assignable, so the error makes sense. The code compiles if I change the data member to a plain <code>char</code> instead of an array.</p>
  
  <p>I cannot replace the array with an <code>std::array</code> or some other container because the structure is being consumed by a C API. The only solution I can think of is to write a couple of wrappers and do the following</p>
  
  <ol>
  <li>a <code>struct S1</code> that duplicates <code>S</code> except it'll have an <code>std::array</code> instead of a C-style array</li>
  <li>A <code>foo_wrapper</code> that accepts a <code>S1 const *</code>, copies the contents over to an <code>S</code> instance and calls <code>foo</code></li>
  <li>Register a <code>to_python_converter</code> to convert the <code>std::array</code> to a Python list</li>
  </ol>
  
  <p>This should work, and I'm not too concerned about the data copying at this point, but it'd be nice if I could avoid it and expose the array directly without having to jump through all these hoops.</p>
  
  <p>So the question is, how can I expose that C-style array data member to Python as a list?</p>