[C++-sig] Output iterator parameters

François Duranleau duranlef at iro.umontreal.ca
Thu Feb 16 21:54:06 CET 2006


Hi!

I have a few functions/member functions to export to Python that pose me 
some problems. They all take at least an output iterator as a parameter, 
e.g.:

template < typename OutputIterator >
OutputIterator
nearest_neighbors( const sample_set& s ,
                    std::size_t k_nearest ,
                    OutputIterator out )
{
     // ...
     return out ;
}

In a previous thread about 'optimizing away calls to the python runtime', 
I also mentioned a similar problem with functor arguments. In that case we 
could handle it using boost::function and a function converting (actually, 
wrapping) Python callable objects to boost::function objects. But we do 
not have such an abstraction class for iterators, although maybe it could 
be possible to write one. Bar that, what could I do? Some "solutions" I 
can see so far are:

- Think about what kind of iterators I will use with this function and 
instantiate and export the function for each iterator type. In this case, 
each time I face a situation were I need a new iterator type, I need to 
add it to my module and recompile.

- Drop the iterator interface and wrap the function so that it will return 
a Python list (for example).

I am sure I am not the only one out there that need to export such kind of 
functions. What do those people do?

-- 
François Duranleau
LIGUM, Université de Montréal

"Just as a drop of water causes ripples in a pond,
  where there is anger and fear, there is conflict."
                                    - Folken, in _The Vision of Escaflowne_


More information about the Cplusplus-sig mailing list