Working stl vector example.
authorRobert Bradshaw <robertwb@math.washington.edu>
Sun, 16 Aug 2009 01:40:03 +0000 (18:40 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Sun, 16 Aug 2009 01:40:03 +0000 (18:40 -0700)
Cython/Compiler/Symtab.py
tests/run/cpp_stl.pyx [new file with mode: 0644]

index 543879344fb7249df6fd7920b7e6f0d0290269bf..6d7b305d79938fcc1d212600ee93039edf823da9 100644 (file)
@@ -393,7 +393,6 @@ class Scope(object):
                     entry.type.scope = scope
                     self.type_entries.append(entry)
         if not scope and not entry.type.scope:
-            print pos
             self.check_for_illegal_incomplete_ctypedef(typedef_flag, pos)
         return entry
     
diff --git a/tests/run/cpp_stl.pyx b/tests/run/cpp_stl.pyx
new file mode 100644 (file)
index 0000000..4b8af28
--- /dev/null
@@ -0,0 +1,34 @@
+__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()
+
+        iterator end()
+        iterator begin()
+
+        int size()
+
+def test_vector(L):
+    cdef vector[int] *V = new vector[int]()
+    for a in L:
+        V.push_back(a)
+    cdef int i
+    for i in range(len(L)):
+        print V.at(i)
+    del V