4
from libcpp.vector cimport vector
5
from libcpp.map cimport map
6
from libcpp.typeinfo cimport type_info
7
from cython.operator cimport typeid
9
def test_cpp_specialization(cython.floating element):
12
>>> test_cpp_specialization[cython.float](10.0)
13
vector[float] * float 10.0
14
>>> test_cpp_specialization[cython.double](10.0)
15
vector[double] * double 10.0
17
cdef vector[cython.floating] *v = new vector[cython.floating]()
19
print cython.typeof(v), cython.typeof(element), v.at(0)
25
cdef const type_info* tidint = &typeid(int)
32
cdef const type_info* a = &typeid(C)
33
return a[0] == tidint[0]
37
def typeid_call2(cython.integral x):
40
>>> typeid_call2[int](1)
43
cdef const type_info* a = &typeid(cython.integral)
44
return a[0] == tidint[0]
46
cdef fused_ref(cython.integral& x):
49
def test_fused_ref(int x):
54
return fused_ref(x), fused_ref[int](x)
56
ctypedef fused nested_fused:
57
vector[cython.integral]
59
cdef vec_of_fused(nested_fused v):
61
return cython.typeof(x)
63
def test_nested_fused():
65
>>> test_nested_fused()
69
cdef vector[int] vi = [0,1]
70
cdef vector[long] vl = [0,1]
71
print vec_of_fused(vi)
72
print vec_of_fused(vl)
74
ctypedef fused nested_fused2:
75
map[cython.integral, cython.floating]
77
cdef map_of_fused(nested_fused2 m):
79
return cython.typeof(pair.first), cython.typeof(pair.second)
81
def test_nested_fused2():
83
>>> test_nested_fused2()
87
cdef map[int, float] mif = { 0: 0.0 }
88
cdef map[long, double] mld = { 0: 0.0 }
89
print map_of_fused(mif)
90
print map_of_fused(mld)