The Python Oracle

Templated STL containers as argument to function in cython

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Unforgiving Himalayas Looping

--

Chapters
00:00 Templated Stl Containers As Argument To Function In Cython
00:43 Accepted Answer Score 2
00:57 Thank you

--

Full question
https://stackoverflow.com/questions/1328...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #cython

#avk47



ACCEPTED ANSWER

Score 2


Use Fused Types.

Example:

cimport cython

ctypedef fused any:
    string
    cython.int

cpdef bool is_in_vector(string a, vector[any] v)

Or this way:

ctypedef fused vector_t:
    vector[string]
    vector[cython.int]

cpdef bool is_in_vector(string a, vector_t v)