|
From: Naveen K. <nav...@gm...> - 2008-08-13 14:27:32
|
On Tue, Aug 12, 2008 at 9:26 PM, Josh Cherry <jc...@nc...>wrote:
>
>
> On Tue, 12 Aug 2008, Naveen Khanna wrote:
>
> I'm facing compilation errors in the generated code when trying to wrap
>> in python a class with static template member function. I have tried with
>> the 1.3.36 release and the current SVN version. G++ version is 4.2.3.
>>
>> I have created a simple test case to reproduce the error
>>
>> --- c++ code ---
>>
>> template<class T>
>> class Foo
>> {
>> public:
>> template<class T1>
>> static T bar(T1 arg1)
>> {
>> return arg1;
>> }
>> };
>>
>> --- swig template instantiation ---
>>
>> %extend Foo
>> {
>> %template(bar) bar<int>;
>> }
>>
>> %template(Foo_int) Foo<int>;
>>
>
> I'm not surprised that this doesn't work. You could do something like
> this:
>
> %extend Foo
> {
> static int bar(int arg1) {
> return Foo<int>::bar(arg1);
> }
> }
>
> Josh
>
>
Thanks for the response,
I have tried your suggestion and confirm it works, but explicitly expanding
every template function like this becomes very tedious when dealing with a
large number of them and it also kind of defeats the entire purpose of using
templates.
I must add that if i edit the generated cpp code to change
'Foo_Sl_int_Sg__bar<(int)>' and 'Foo_Sl_int_Sg__bar<int>' to just
'Foo_Sl_int_Sg__bar' then it compiles without errors and the resultant
static method works from python as expected. So looks like the problem can
be fixed by fixing the code generation. Member function templates and static
member functions inside a template class work with out problems when used
separately and the problem occurs only when they are combined.
Regards
Naveen
|