Michel Dupront | 2 Aug 2012 15:23
Picon
Favicon

class template with a template constructor


Hello,

 I just cannot swig to python the following piece of code.
The issue is the template constructor. 

template <class T>
class Foo
{
 template <class P> Foo( P p, ... ) ....
}

Any help would be very much appreciated.
Thanks in advance.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user
William S Fulton | 2 Aug 2012 21:44
Picon
Favicon
Gravatar

Re: class template with a template constructor

On 02/08/12 14:23, Michel Dupront wrote:
>
> Hello,
>
> I just cannot swig to python the following piece of code.
> The issue is the template constructor.
>
> template <class T>
> class Foo
> {
> template <class P> Foo( P p, ... ) ....
> }
>

Look for conversion constructor in docs at 
http://www.swig.org/Doc2.0/SWIGPlus.html#SWIGPlus_nn30

%inline %{
template <class T>
class Foo
{
public:
    template <class P> Foo(P p) {}
};
%}

%extend Foo<int> {
   %template() Foo::Foo<double>;
}

%template(FooInt) Foo<int>;

You can give a name if you like in the first %template.

William

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
Michel Dupront | 3 Aug 2012 09:56
Picon
Favicon

Re: class template with a template constructor

Thank for your answer.

It is working fine with a P template member function if the constructor
does not depend on the P template.
But I cannot make it work when the constructor depends on the
P template.
It goes through the compilation, ...
but when I tried an instantiation I have an error message telling me
"AttributeError: No constructor defined"



> Date: Thu, 2 Aug 2012 20:44:47 +0100
> From: wsf <at> fultondesigns.co.uk
> To: michel.dupront <at> hotmail.fr
> CC: swig-user <at> lists.sourceforge.net
> Subject: Re: [Swig-user] class template with a template constructor
>
> On 02/08/12 14:23, Michel Dupront wrote:
> >
> > Hello,
> >
> > I just cannot swig to python the following piece of code.
> > The issue is the template constructor.
> >
> > template <class T>
> > class Foo
> > {
> > template <class P> Foo( P p, ... ) ....
> > }
> >
>
> Look for conversion constructor in docs at
> http://www.swig.org/Doc2.0/SWIGPlus.html#SWIGPlus_nn30
>
> %inline %{
> template <class T>
> class Foo
> {
> public:
> template <class P> Foo(P p) {}
> };
> %}
>
> %extend Foo<int> {
> %template() Foo::Foo<double>;
> }
>
> %template(FooInt) Foo<int>;
>
> You can give a name if you like in the first %template.
>
> William
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Swig-user mailing list
Swig-user <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/swig-user

Gmane