Commit eeacfc75 authored by Robert Bradshaw's avatar Robert Bradshaw

Nested classes example.

parent ccda96cb
......@@ -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))
......
__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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment