logo       

Typedefs of template instantiations not recognized properly?: msg#00122

programming.swig

Subject: Typedefs of template instantiations not recognized properly?

Zachary Pincus writes:
> The typedef resolution mechanism seems (in my hands) to play poorly
> with namespaces and/or the template mechanism.
>
> I've got a SWIG interface similar to:
> ----------------
>
> namespace A {
> struct OpaqueStruct;
> typedef struct OpaqueStruct OpaqueType;
> typedef std::vector<OpaqueType> OpaqueVectorType;
>
> void FillVector(OpaqueVectorType);
> }
>
> %template(OpaqueVectorType) std::vector<A::OpaqueType>;
>
> ----------------
>
> Now, when I use the wrapper as follows:
> >>> vec = SwigModule.OpaqueVectorType()
> >>> SwigModule.FillVector(vec)
>
> I get the following error:
> Type error. Got _p_std__vectorTA__OpaqueType_t, expected
> _p_A__OpaqueVectorType
>
> That is, the wrapper code doesn't realize that std::vector<OpaqueType>
> and A::OpaqueVectorType are the same thing!
>
> I can't really figure out if the problem is due to the template
> mechanism, the typedef mechanism, or throwing namespaces into the mix.
> (It doesn't matter whether the %template line is above or below the
> namespace definition.)

It would be *highly* advisable to use %template after the namespace
definition and everything else is defined. Make sure "std" is
defined as a namespace too.

> Any thoughts? Is this a known issue? Am I just doing something wrong?
> Basically, is there anything I can do, short or find/replace on the
> interface files to get rid of the need for the typedefs?

There are known bugs in namespace/template mechanism (at least there
were some broken tests in the test-suite the last time I checked).
I don't know whether the case above is one of them, but the
implementation is by no means bug free. Please submit to the bug
tracker if you can't get it to work.

-- Dave
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise