> > We have a lot of C++ code using a home-grown Event<T> class template. An
> > Event<T> is just a list of pointers to callback function objects. More
> > precisely, an Event<T> is a std::list<unary_function<T>*>, where
> > unary_function is a polymorphic function object class. Code that
> > generates an event iterates through the list, dereferences each pointer
> > and calls the corresponding function.
> >
> > I'd like python code to be able to generate these C++ events. To do that
> > Event<>s need to support Python's iterable interface, which requires
> > random access to the container.Unfortunately, std::list<> doesn't
> > support random access. Short of copying the contents of every
> > std::list<> to a std::vector<> for Python's benefit I don't see how this
> > can be accomplished.
> >
> > Does anyone have any ideas for a simpler, more natural implementation?
> >
>
> You don't need random access to make a python iterable at all - Python's 
> built-in dict and set types are examples.  All you need to do is define an 
> __iter__ special function, and you should be able to do that fairly 
> automatically using the stuff described here:
>
> http://www.boost.org/doc/libs/1_43_0/libs/python/doc/v2/iterator.html
> Jim Bosch

I often refer to this page when I want to add the __iter__ function.
It clearly shows all the available options.
http://wiki.python.org/moin/boost.python/iterator

Add to that boost::make_transform_iterator and possibilities are endless ;)
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to