From: Robert Bradshaw Date: Sun, 21 Feb 2010 04:38:58 +0000 (-0800) Subject: Nested classes example. X-Git-Tag: 0.13.beta0~337 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=eeacfc75216da964883237e49b2600499cda790a;p=cython.git Nested classes example. --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index d9e21176..c3902b4e 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -4230,8 +4230,7 @@ class UnopNode(ExprNode): type = self.operand.type if type.is_ptr or type.is_reference: type = type.base_type - entry = env.lookup(type.name) - function = entry.type.scope.lookup("operator%s" % self.operator) + function = type.scope.lookup("operator%s" % self.operator) if not function: error(self.pos, "'%s' operator not defined for %s" % (self.operator, type)) diff --git a/tests/run/cpp_stl.pyx b/tests/run/cpp_stl.pyx index 93a442af..66ecf688 100644 --- a/tests/run/cpp_stl.pyx +++ b/tests/run/cpp_stl.pyx @@ -1,34 +1,52 @@ -__doc__ = u""" - >>> test_vector([1,10,100]) - 1 - 10 - 100 -""" - cdef extern from "vector" namespace "std": - cdef cppclass iterator[T]: - pass - cdef cppclass vector[T]: - #constructors - __init__() T at(int) void push_back(T t) void assign(int, T) void clear() + int size() + + cppclass iterator: + T operator*() + iterator operator++() + bint operator==(iterator) + bint operator!=(iterator) iterator end() iterator begin() - int size() +from cython.operator cimport dereference as deref, preincrement as inc def test_vector(L): - cdef vector[int] *V = new vector[int]() + """ + >>> test_vector([1,10,100]) + 1 + 10 + 100 + """ + v = new vector[int]() for a in L: - V.push_back(a) + v.push_back(a) cdef int i for i in range(len(L)): - print V.at(i) - del V + print v.at(i) + del v + +def test_vector_iterator(L): + """ + >>> test_vector([11, 37, 389, 5077]) + 11 + 37 + 389 + 5077 + """ + v = new vector[int]() + for a in L: + v.push_back(a) + cdef vector[int].iterator iter = v.begin() + while iter != v.end(): + print deref(iter) + inc(iter) + del v