I posted this to sourceforge as well, any ideas?
I have written a function in cython that will search a STL vector of
strings for a given string and return true if it is found, false otherwise.
Performance is very important here! I would ideally like to have a
templated function to do the same thing for vectors of integers or double
values so I don't have to write a function for each data type. I am sure
this is possible but I don't know the cython syntax for templated
functions. (I know how to do it in c++)
from libcpp cimport boolfrom libcpp.string cimport stringfrom
libcpp.vector cimport vectorfrom cython.operator cimport dereference
as deref, preincrement as inc
cpdef bool is_in_vector(string a, vector[string] v):
cdef vector[string].iterator it = v.begin()
while it != v.end():
if deref(it) == a:
return True
#Increment iterator
inc(it)
return False
Thanks,
Ian