[C++-sig] Iterator or not iterator...

Cyril Bazin cyril.bazin at info.unicaen.fr
Thu Jun 22 10:46:55 CEST 2006


I've got a question about the bindings of iterators.

Given a C++ code which look more or less like that:

template <class O>
class C {
    It<O> the_begin() {...}

    It<O> the_end() {...}

    It2<O> foo(it<O>) {...}


template <class O>
class It {
   //... define everything that an iterator must define ...

The C++ code to bind a version of the previous class C could be :

class MyO {
   //define some methods

typedef C<MyO>      MyC;
typedef It<MyO>       MyIt;


//class _<MyIt>("MyIt")
//       .def(...)
//       ...;

        .def("the_iter", range(&MyC::the_begin , &MyC::the_end))
        .def("foo", MyC::foo)

As expected, in Python the method MyC.the_iter will return some instances of
the class MyO.
But, the method MyC::foo expect a MyIt as argument... So, I can't do
something like that :

myC = MyC()
for bar in myC:
    assert type(bar) == MyO
    x = myC.foo(bar)

In other words, Is there a way to define MyC like that :
        .def("the_iter", range_bis(&MyC::the_begin , &MyC::the_end))

Which could allow me to do something like:
myC = MyC()
for bar in myC:
    assert type(bar) == MyIt
    x = myC.foo(bar)

If you have any suggestion...

Thanks in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060622/99f415e6/attachment.htm>

More information about the Cplusplus-sig mailing list