Template function support

173 views
Skip to first unread message

IAmTonan

unread,
Nov 11, 2011, 7:25:58 PM11/11/11
to cython-users
Hello,

I was wondering if there is currently any support for template
functions. If not are there any plans to add this feature in the
future? I'm getting some great results as is but template functions
would take it over the top.

Thanks!

-tony

mark florisson

unread,
Nov 12, 2011, 6:18:48 AM11/12/11
to cython...@googlegroups.com

In the upcoming release we'll get fused types, which may do what you
want. This page describes how you can use them and what you can do
with them: https://sage.math.washington.edu:8091/hudson/job/cython-docs/doclinks/1/src/userguide/fusedtypes.html

To use them right now you'll need to checkout cython from github
(https://github.com/cython/cython).

Tony Barbieri

unread,
Nov 12, 2011, 12:46:51 PM11/12/11
to cython...@googlegroups.com
These look very close.  Is it possible to wrap template functions that have been defined in cpp classes externally?  The only reason I ask is I didn't see any examples so I wasn't sure if that was supported....I'm not sure how one would define the template function in the cppclass definition.  My basic issue is I have a cpp API that uses quite a bit of function templating. 

This does look very interesting though!  Thanks!

-tony
--
-tony

mark florisson

unread,
Nov 13, 2011, 10:33:51 AM11/13/11
to cython...@googlegroups.com
You can't really use fused types to specify C++ templates, but you can
specialize C++ objects with a specialization of a fused type. e.g. one
may do this:

def func(cython.floating arg):
cdef mycpptype[cython.floating] cppobj = new mycpptype[cython.floating]()
...

You can only specialize fused types through function parameters
currently, so you cannot use fused types as part of structs, cdef
classes or to define C++ templates. I'm not sure if the above does
what you want, but perhaps you want to see my other post:
http://groups.google.com/group/cython-users/browse_thread/thread/a90a4ca3784642a2

Reply all
Reply to author
Forward
0 new messages