2
# tag: cpp, werror, no-cpp-locals
4
from cython.operator import dereference as deref
5
from libcpp.pair cimport pair
6
from libcpp.vector cimport vector
8
cdef extern from "cpp_template_subclasses_helper.h":
12
cdef cppclass A[A1](Base):
15
cdef cppclass B[B1, B2](A[B2]):
16
pair[B1, B2] funcB(B1, B2)
18
cdef cppclass C[C1](B[long, C1]):
21
cdef cppclass D[D1](C[pair[D1, D1]]):
24
cdef cppclass E(D[double]):
33
cdef A[double] *a = NULL
37
assert base.name() == b"A", base.name()
49
cdef B[long, double] *b = NULL
51
base = a = b = new B[long, double]()
52
assert base.name() == b"B", base.name()
53
assert a.funcA(y) == y
54
assert <object>b.funcB(x, y) == (x, y)
60
>>> testC(37, [1, 37])
61
>>> testC(25, [1, 5, 25])
62
>>> testC(105, [1, 3, 5, 7, 15, 21, 35, 105])
65
cdef A[vector[long]] *a
66
cdef B[long, vector[long]] *b
67
cdef C[vector[long]] *c = NULL
69
base = a = b = c = new C[vector[long]]()
70
assert base.name() == b"C", base.name()
71
assert <object>a.funcA(y) == y
72
assert <object>b.funcB(x, y) == (x, y)
73
assert <object>c.funcC(y) == y
84
cdef A[pair[double, double]] *a
85
cdef B[long, pair[double, double]] *b
86
cdef C[pair[double, double]] *c
87
cdef D[double] *d = NULL
89
base = a = b = c = d = new D[double]()
90
assert base.name() == b"D", base.name()
91
assert <object>a.funcA((y, y)) == (y, y)
92
assert <object>b.funcB(x, (y, y + 1)) == (x, (y, y + 1))
93
assert <object>c.funcC((y, y)) == (y, y)
104
cdef A[pair[double, double]] *a
105
cdef B[long, pair[double, double]] *b
106
cdef C[pair[double, double]] *c
110
base = a = b = c = d = e = new E()
111
assert base.name() == b"E", base.name()
112
assert <object>a.funcA((y, y)) == (y, y)
113
assert <object>b.funcB(x, (y, y + 1)) == (x, (y, y + 1))
114
assert <object>c.funcC((y, y)) == (y, y)
119
cdef public pair[int, double] public_return_pair(a, b) except *:
120
return pair[int, double](a, b)
122
def test_GH1599(a, b):
124
>>> test_GH1599(1, 2)
127
return public_return_pair(a, b)
130
# Related to GH Issue #1852.
132
cdef cppclass Callback[T]:#(UntypedCallback):
135
cdef cppclass MyClass[O]:
136
void Invoke(Callback[O]*)
138
cdef cppclass MySubclass[T](MyClass[T]):
139
void Invoke(Callback[T]* callback):
143
cdef cppclass Getter[T]:
144
T get(bint fire) except *:
148
raise NotImplementedError
150
cdef cppclass GetInt(Getter[int]):
151
int get(bint fire) except *:
157
def test_subclass_exception_values(bint fire):
159
>>> test_subclass_exception_values(False)
161
>>> test_subclass_exception_values(True)
162
Traceback (most recent call last):
167
return getter.get(fire)