From e0814f76a508d1f1da11eb70468a9bcc53633f6d Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Tue, 5 Oct 2010 14:35:12 -0300 Subject: [PATCH] fixes, additions and tests for libcpp.vector --- Cython/Includes/libcpp/vector.pxd | 12 ++++++-- tests/run/cpp_stl_vector.pyx | 48 +++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/Cython/Includes/libcpp/vector.pxd b/Cython/Includes/libcpp/vector.pxd index 0a6ba1f0..61c6aefb 100644 --- a/Cython/Includes/libcpp/vector.pxd +++ b/Cython/Includes/libcpp/vector.pxd @@ -6,12 +6,20 @@ cdef extern from "" 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): diff --git a/tests/run/cpp_stl_vector.pyx b/tests/run/cpp_stl_vector.pyx index eee6ef89..4e03706b 100644 --- a/tests/run/cpp_stl_vector.pyx +++ b/tests/run/cpp_stl_vector.pyx @@ -1,11 +1,7 @@ from cython.operator cimport dereference as d +from cython.operator cimport preincrement as incr -cdef extern from "" 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 -- 2.26.2