Dag Sverre Seljebotn wrote: > Robert Bradshaw wrote: >> On Apr 26, 2009, at 9:53 AM, Dag Sverre Seljebotn wrote: >>> 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). > > The BIGGEST problem I see with C++ support in Cython right now lies > right here. I beg you to make sure you fully understand this. > > The issue is that vector<T>::iterator does not have a no-arg constructor. > > I.e. it is legal to do > > vector<int>::iterator it = vec.begin() > > but this gives a compilation error: > > vector<int>::iterator it; > > So, to get it to work, one must basically do > > vector<int>::iterator* it = NULL; > ...even get hold of vec somehow... > *it = vec.begin() > ... now, first element in vec is **it
Ouch. That obviously does not work. It should be this: vector<int>::iterator* it = NULL; ... get vec it = new vector<int>::iterator(vec.begin()); ... use it, value is in **it delete it; -- Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
