title: Iterating over C++ objects wrapped in Python via pybind11
body: <p>I have C++ code defining a <code>curves</code> class, a <code>curve</code> class and a <code>point</code> class, I'm trying to write Python bindings for those classes via pybind11 and use them in Python. </p>
  
  <p>The pybind11 bindings for these classes look like this:</p>
  
  <pre><code>namespace py = pybind11;
  
  PYBIND11_MODULE(mymodule, m) {
      py::class_&lt;_point&gt;(m, "_point")
          .def(py::init&lt;double, double&gt;()) 
          .def_readwrite("next", &amp;point::next)
          .def_readwrite("prev", &amp;point::prev)
          .def_readonly("x1", &amp;point::x1)
          .def_readonly("x2", &amp;point::x2);
      py::class_&lt;curve&gt;(m, "curve")
          .def(py::init&lt;point*&gt;()) //constructor 1
          .def(py::init()) //constructor 2
          .def_readwrite("first", &amp;curve::first)
          .def_readwrite("last", &amp;curve::last)
          .def_readwrite("next", &amp;curve::next)
          .def_readwrite("prev", &amp;curve::prev);
      py::class_&lt;curves&gt;(m, "curves")
          .def(py::init()) 
          .def_readwrite("first", &amp;curves::first)
          .def_readwrite("last", &amp;curves::last);
  }
  </code></pre>
  
  <p>In C++ I can iterate over a <code>curves</code> object which is made up of <code>curve</code> 
  which in turn is made up of <code>point</code> objects in the following way:</p>
  
  <pre><code>for(curve *c=curves_pointer-&gt;first; c; c=c-&gt;next) {
        for(point *p=c-&gt;first; p; p=p-&gt;next) {
            cout &lt;&lt; p-&gt;x1 &lt;&lt; "," &lt;&lt;p-&gt;x2 &lt;&lt; std::endl;
        }
  }
  </code></pre>
  
  <p>In Python, I can for example access a single point with <code>curves_instance.last.first.x1</code>, but I don't know how to iterate over all curves, points etc.</p>