Note that there are some explanatory texts on larger screens.

plurals
  1. POSWIG %ignore doesn't match template with typedef
    text
    copied!<p>I have a templated Vector (as in a mathematical vector, not a std::vector) class which can be instantiated with a size between 2 and 4. The definition is something like:</p> <pre><code>template &lt;uint32_t Size, typename StorageType&gt; class Vector { public: Vector(StorageType x, StorageType y); Vector(StorageType x, StorageType y, StorageType z); Vector(StorageType x, StorageType y, StorageType z, StorageType w); ... }; </code></pre> <p>In my SWIG file, I want to wrap a version which has a <code>Size</code> of <code>3</code> and a <code>StorageType</code> of <code>int8_t</code> and so I do</p> <pre><code>%module Vector %{ #include "Vector.h" %} %include "stdint.i" %include "Vector.h" %ignore Vector(int8_t, int8_t); %ignore Vector(int8_t, int8_t, int8_t, int8_t); %template(Vector3DInt8) PolyVox::Vector&lt;3,int8_t&gt;; </code></pre> <p>But it fails to <code>%ignore</code> the requested constructors.</p> <p>It seems that SWIG, inside the <code>%template</code> macro automatically 'strips off' typedefs from template parameters and so <code>%template(Vector3DInt8) PolyVox::Vector&lt;3,int8_t&gt;;</code> actually gets converted to <code>%template(Vector3DInt8) PolyVox::Vector&lt;3,unsigned char&gt;;</code>. Because of this, the <code>%ignore</code> doesn't match since <code>unsigned char</code> doesn't match <code>int8_t</code>.</p> <p>If I add a <code>static_assert()</code> inside one of the functions I want to be ignored, I get:</p> <pre><code>source/Vector.inl: In constructor ‘Vector&lt;Size, StorageType&gt;::Vector(StorageType, StorageType) [with unsigned int Size = 3u, StorageType = signed char]’: build/PolyVoxCorePYTHON_wrap.cxx:6446:100: instantiated from here source/Vector.inl:56:3: error: static assertion failed: "This constructor should only be used for vectors with two elements." </code></pre> <p>I've also tried to use <code>-notemplatereduce</code> but it seems to have no effect.</p> <p>Is there a way to get SWIG to correctly ignore the unwanted constructors?</p> <p>Edit: I'm using GCC 4.5 with SWIG 2.0.8</p> <p>Edit 2: Added <code>stdint.i</code> to <code>.i</code> file as it is needed for Python typemaps. Without the <code>stdint.i</code>, the <code>%ignore</code> works correctly but it is needed to actually use the bindings in Python.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload