Nested classes example.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 21 Feb 2010 04:38:58 +0000 (20:38 -0800)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 21 Feb 2010 04:38:58 +0000 (20:38 -0800)
Cython/Compiler/ExprNodes.py
tests/run/cpp_stl.pyx

index d9e2117692969fe15679ee66a5c5b7e8327ef75c..c3902b4e92f5d3a5b7bf4d3b51390734a0c61448 100755 (executable)
@@ -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))
index 93a442af4fdccb27204a7f0c5f939d30a5c680f5..66ecf6885d3cf3023d0842592ed980f0e7e8ee77 100644 (file)
@@ -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