[C++-sig] Exposing std::list<> via Boost.Python

Phil Bass pab at isotek.co.uk
Mon Jun 21 16:01:40 CEST 2010


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?

-- 
Phil Bass (pab at isotek.co.uk)

     The views expressed in this e-mail/posting are those of the author
     and do not necessarily reflect those of Isotek Electronics Ltd.




More information about the Cplusplus-sig mailing list