Commit e0814f76 authored by Lisandro Dalcin's avatar Lisandro Dalcin

fixes, additions and tests for libcpp.vector

parent 3cf1d712
......@@ -6,12 +6,20 @@ cdef extern from "<vector>" namespace "std":
iterator operator--()
bint operator==(iterator)
bint operator!=(iterator)
bint operator< (iterator)
bint operator> (iterator)
bint operator<=(iterator)
bint operator>=(iterator)
cppclass reverse_iterator:
T& operator*()
iterator operator++()
iterator operator--()
bint operator==(iterator)
bint operator!=(iterator)
bint operator==(reverse_iterator)
bint operator!=(reverse_iterator)
bint operator< (reverse_iterator)
bint operator> (reverse_iterator)
bint operator<=(reverse_iterator)
bint operator>=(reverse_iterator)
#cppclass const_iterator(iterator):
# pass
#cppclass const_reverse_iterator(reverse_iterator):
......
from cython.operator cimport dereference as d
from cython.operator cimport preincrement as incr
cdef extern from "<vector>" namespace "std":
cdef cppclass vector[T]:
void push_back(T)
size_t size()
T& operator[](size_t)
from libcpp.vector cimport vector
def simple_test(double x):
"""
......@@ -71,3 +67,43 @@ def index_set_test(L):
return d(v)[0], d(v)[v.size()-1]
finally:
del v
def iteration_test(L):
"""
>>> iteration_test([1,2,4,8])
1
2
4
8
"""
try:
v = new vector[int]()
for a in L:
v.push_back(a)
it = v.begin()
while it != v.end():
a = d(it)
incr(it)
print(a)
finally:
del v
def reverse_iteration_test(L):
"""
>>> reverse_iteration_test([1,2,4,8])
8
4
2
1
"""
try:
v = new vector[int]()
for a in L:
v.push_back(a)
it = v.rbegin()
while it != v.rend():
a = d(it)
incr(it)
print(a)
finally:
del v
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment