template function not wrapped

View: New views
2 Messages — Rating Filter:   Alert me  

template function not wrapped

by Uli Mewes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
here comes my next question while learning swig. Thanks a lot for your recent help!

I have to wrap a function like this:
template<class Type> A<B<Type> > foobar();

Because the function foobar() is completely missing in foo_wrap.cxx, I removed one templating level and tested the following foo.i:
%module foo
template<class T1> class A{};
template<class T2> class B{}; //unused while testing
template<class Type>  B<Type>  foobar();

Still there is no foobar() in foo_wrap.cxx. Replacing the last line with "B<int> foobar();" gives the expected function.
The command "swig -c++ -python foo.i" didn't output any warnings or errors or anything..
What's wrong? Is it a limitation of swig with respect to templates?

Regards
Uli



      __________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang..
http://de.overview.mail.yahoo.com


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Parent Message unknown Re: template function not wrapped

by Uli Mewes :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>%module foo
>template<class T1> class A{};
>template<class T2> class B{}; //unused while testing
>template<class Type>  B<Type>  foobar();
>
>Still there is no foobar() in foo_wrap.cxx

Well, after I rtfm ;-) I found the answer myself. Swig must instantiate the template function with the "%template" instruction to generate a wrapper. HTH some other newbie, here is the correct code:

template<class T1> class A{}; // actually this is unused, but who cares?
template<class T2> class B{};
%template(intB) B<int>; // instantiate a B<int>
template<class Type> B<Type> foobar();
%template(intfoobar) foobar<intB>; // instantiate a foobar<B<int> >

Regards
Uli



      __________________________________________________________
Gesendet von Yahoo! Mail.
Dem pfiffigeren Posteingang..
http://de.overview.mail.yahoo.com


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user