On Apr 26, 2009, at 9:53 AM, Dag Sverre Seljebotn wrote: > Danilo Freitas wrote: >> As I said before, I prefer a Pythonic syntax for Cython. >> So, deref() would be better in this case. >> But, for all this and more, we need to define a default syntax. >> Mixing syntax is a little weird and harder to use. >> >> If we translate C++ syntax to Pythonic syntax, I think it will be >> easier to use it. >> >> So, if we gonna do it, many other functions will be added to the >> list. >> I have some Ideas. Don't know if they are good. But it sounds like: >> >> my_list = clist(int) #just an example >> it = cython.get_begin_iterator(my_list) >> while it != cython.get_end_iterator(my_list): >> if something == cython.deref(it): #just a normal if >> break >> cython.inc(it) >> >> So, we could get iterator fom many ways. Just like in STL. > > Yes. (Though my vote is for my_list.begin() and my_list.end() > instead.)
Yes, this doesn't take anything special. > The main issue with using STL iterators in Cython though is what types > to add. > > > For comparison, this is how it is /currently/ possible in Cython to > do this: > > # the proper extern declarations > > # use vector in example, then we don't need inc/dec/deref > > cdef cpp_vector_int* vec = new_cpp_vector_int() > cdef cpp_vector_int_iterator* it = \ > new_cpp_vector_int_iterator(vec.begin()) > cdef cpp_vector_int_iterator* end = \ > new_cpp_vector_int_iterator(vec.end()) > > while it[0] != end[0]: > if something = it[0][0]: > break > it[0] += 1 > > cpp_delete(it) > cpp_delete(end) > cpp_delete(vec) > > > Not pretty. The types are the problem -- if one could simply do > > cdef cpp_vector_int_iterator it = vec.begin() > > things would look much nicer. What is the obstruction to this? One should be able to declare the vector<T> class as having a begin method returning an iterator<T>, it's all about templates, not operators (well the initializing of it at least). - Robert _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
