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):
"""
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