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

There seems to be two solutions, of which I strongly dislike one and 
like the other.

The one I strongly dislike:

I,ntroduce C++ variable scoping in Cython (otherwise you cannot supply 
the constructor arguments when you have them, and run the destructor at 
the right time)

The one I like is here, under "Stack allocation":
http://wiki.cython.org/enhancements/cpp


-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to