Python has no built-in equivalent to OutputIterator; in particular, embedded or standard library containers do not support any common interface that allows client code to send data to them without knowing the specific type of container.
According to @Steven Rumbalski comment and @Glenn Maynard answer , this is usually not a problem, because a function that would accept the OutputIterator argument in C ++ would simply be written as a generator in python.
Usually I have no problem using generators and I never felt like I needed an OutputIterator in Python. However, in this case I am stuck.
I am reprogramming in Python some of the algorithms from the Boost Graph library. A typical graph traversal algorithm, such as depth_first_search , takes a visitor object as a parameter. A visitor is, in fact, a bunch of callback functions that the traversal algorithm calls when it encounters various events during its execution (for example, it detects a new vertex, examines an edge, etc.). In C ++, I have one or more of these callback functions that send data to the OutputIterator objects that the visitor object received when it was initialized from the client code. (For example, how exactly topological_sort is implemented: it receives an OutputIterator, passes it to the dfs_visitor object, the visitor then โtracksโ the finished_vertex event and sends the vertices received to it to the specified OutputIterator. Of course, more complex cases require several OutputIterator objects and several callback functions.)
How to achieve the same result with Python generators?
I need to somehow send the data in the "style" of the generator, from depth_first_search to several designated data consumers. I just can't figure out how to do this. (I am using Python 3.3.)
max
source share