Document improved template explicit specialization and partial specialization

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11713 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2009-10-23 06:48:38 +00:00
commit 6fc2ce82ea

View file

@ -3246,22 +3246,39 @@ public:
</div> </div>
<p> <p>
SWIG should be able to handle most simple uses of partial specialization. However, it may fail SWIG supports both template explicit specialization and partial specialization. Consider:
to match templates properly in more complicated cases. For example, if you have this code,
</p> </p>
<div class="code"> <div class="code">
<pre> <pre>
template&lt;class T1, class T2&gt; class Foo&lt;T1, T2 *&gt; { }; template&lt;class T1, class T2&gt; class Foo { }; // (1) primary template
template&lt;&gt; class Foo&lt;double *, int *&gt; { }; // (2) explicit specialization
template&lt;class T1, class T2&gt; class Foo&lt;T1, T2 *&gt; { }; // (3) partial specialization
</pre> </pre>
</div> </div>
<p> <p>
SWIG isn't able to match it properly for instantiations like <tt>Foo&lt;int *, int *&gt;</tt>. SWIG is able to properly match explicit instantiations:
This problem is not due to parsing, but due to the fact that SWIG does not currently implement all
of the C++ argument deduction rules.
</p> </p>
<div class="code">
<pre>
<tt>Foo&lt;double *, int *&gt;</tt> // explicit specialization matching (2)
</pre>
</div>
<p>
SWIG implements template argument deduction so that the following partial specialization examples work just like they would with a C++ compiler:
</p>
<div class="code">
<pre>
<tt>Foo&lt;int *, int *&gt;</tt> // partial specialization matching (3)
<tt>Foo&lt;int *, const int *&gt;</tt> // partial specialization matching (3)
<tt>Foo&lt;int *, int **&gt;</tt> // partial specialization matching (3)
</pre>
</div>
<p> <p>
Member function templates are supported. The underlying principle is the same Member function templates are supported. The underlying principle is the same
as for normal templates--SWIG can't create a wrapper unless you provide as for normal templates--SWIG can't create a wrapper unless you provide