Reputation: 1031
I have a template function with following signature in c++ file
template <class T> std::vector<T> function(T);
I wanna make an interface file to wrap main.cpp to a python file with Swig. How should I include Tfunction in Swig, for types int float and double?
//main.i
%module main
%include "carrays.i"
%array_class(double, doubleArray);
%{
extern template <class T> std::vector<T> Tfunction(T);
%}
extern template <class T> std::vector<T> Tfunction(T);
Upvotes: 1
Views: 1743
Reputation: 29493
Since Python does not know templates, you have to create a type for each parameter. There is a convenient %template directive you would use:
%template(TfunctionInt) Tfunction<int>;
This is explained in detail in section 6.18 of SWIG docs.
Upvotes: 3