[C++-sig] expose python iterators to c++?
François Duranleau
duranlef at iro.umontreal.ca
Thu Feb 15 16:26:19 CET 2007
> On Wed, 14 Feb 2007, Neal Becker wrote:
> > François Duranleau wrote:
[...]
> > http://tinyurl.com/24dpdf
[...]
I added a simple use test in Python (forgot the first time).
> Looks very interesting. One thing I'm not sure about. Do I understand
> correctly that an python object is convertible to a c++ range iff
> PyObject_GetIter( obj )? I think it needs also that deref the iterator
> produces the correct type.
We should. However, because Python's sequences can contain objects of
heterogenous types, we would actually need to test all objects in the
sequence. But granted, only testing the first item could be a simple
heuristic to avoid common errors.
> In range_test.cpp:
> typedef ::pyfdl::range< int > range_int_type ;
>
> Don't we need different converters for range<int>, range<double>, etc?
Yes, of course. That typedef was just a sample use when you need an
iterator over integer values (that's laziness from me for not writing
comments in the example). Whenever you need to export a function requiring
ranges or pairs of iterators, you would also need to call
range_from_and_to_python for all required types in your application.
--
François Duranleau
LIGUM, Université de Montréal
More information about the Cplusplus-sig
mailing list