[C++-sig] Re: custom iterator object

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Nov 7 22:12:57 CET 2002


--- Mike Rovner <mike at bindkey.com> wrote:
> I have problems with return value. In __iter__ I have to return self, but
> there is no Python self yet in wrapping class.
> So probably I have to duplicate part of the BPL iterator guts, but I got
> lost :(

You could try this:

  inline
  boost::python::object
  pass_through(boost::python::object const& o) { return o; }

      class_<w_t>(python_name)
        .def("next", next)
        .def("__iter__", pass_through)
      ;

Full source:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/cctbx/scitbx/include/scitbx/boost_python/iterator_wrappers.h

Ralf


__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2




More information about the Cplusplus-sig mailing list