title: Cython cdef class with C++ vector of C++ stack objects
body: <p>In Cython it's really easy to create a Python extensions class of C++ vector of <code>int</code></p>
  <pre class="lang-py prettyprint-override"><code># vector_int.pyx
  
  # distutils: language = c++
  from libcpp.stack cimport stack
  from libcpp.vector cimport vector
  cdef class VectorInt:
      cdef vector[int] v
      
      def __cinit__(self, count):
          self.v = [0] * count  # &lt;-- Works! Allocate variable length of zeros
  
      def set(self, idx, x):
          self.v[idx] = x
  
      def get(self, idx):
          return self.v[idx]
      
  
  def test_vector_int_stack():
      v = VectorInt(11)
      v.set(0, 42)
      assert v.get(0) == 42
  </code></pre>
  <p>But how do I create a Python extension class of <strong>vector of stack objects of int</strong>?</p>
  <pre class="lang-py prettyprint-override"><code># vector_stack_int.pyx
  
  # distutils: language = c++
  from libcpp.stack cimport stack
  from libcpp.vector cimport vector
  
  cdef class VectorStackInt:
  
      cdef vector[stack[long]] v
      
      def __cinit__(self, count):
          for i in range(count):
              self.v.push_back((new stack[long]()))  # &lt;--- Error here?!
  
      def set(self, idx, x):
          self.v[idx].push(x)
  
      def get(self, idx):
          return self.v[idx].top()
  </code></pre>
  <p>This fails because <code>new</code> returns a pointer to the new stack,</p>
  <pre><code>Error compiling Cython file:
  ------------------------------------------------------------
  ...
  
      cdef vector[stack[long]] v
      
      def __cinit__(self, count):
          for i in range(count):
              self.v.push_back((new stack[long]()))  # &lt;--- Error here?!
                                              ^
  ------------------------------------------------------------
  
  pvtracec/libs/simple.pyx:58:45: Cannot assign type 'stack[long] *' to 'stack[long]'
  </code></pre>