cython
1# mode: run
2# tag: cpp, werror, cpp11, no-cpp-locals
3
4from cython.operator cimport dereference as deref
5from cython.operator cimport preincrement as incr
6
7from libcpp.forward_list cimport forward_list
8from libcpp cimport bool as cbool
9
10
11def simple_iteration_test(L):
12"""
13>>> iteration_test([1,2,4,8])
148
154
162
171
18>>> iteration_test([8,4,2,1])
191
202
214
228
23"""
24cdef forward_list[int] l
25for a in L:
26l.push_front(a)
27for a in l:
28print(a)
29
30def iteration_test(L):
31"""
32>>> iteration_test([1,2,4,8])
338
344
352
361
37>>> iteration_test([8,4,2,1])
381
392
404
418
42"""
43l = new forward_list[int]()
44try:
45for a in L:
46l.push_front(a)
47it = l.begin()
48while it != l.end():
49a = deref(it)
50incr(it)
51print(a)
52finally:
53del l
54
55def test_value_type(x):
56"""
57>>> test_value_type(2)
582.0
59>>> test_value_type(2.5)
602.5
61"""
62cdef forward_list[double].value_type val = x
63return val
64
65def test_value_type_complex(x):
66"""
67>>> test_value_type_complex(2)
68(2+0j)
69"""
70cdef forward_list[double complex].value_type val = x
71return val
72
73
74# Tests GitHub issue #1788.
75cdef cppclass MyForwardList[T](forward_list):
76pass
77
78cdef cppclass Ints(MyForwardList[int]):
79pass
80