Update variadic templates

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@13863 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-10-04 20:52:51 +00:00
commit 6a43934ece
2 changed files with 20 additions and 11 deletions

View file

@ -500,7 +500,7 @@ union P {
<H3><a name="Cpp0x_Variadic_templates"></a>7.2.17 Variadic templates</H3>
<p>SWIG fully supports the variadic templates syntax (inside the &lt;&gt;
<p>SWIG supports the variadic templates syntax (inside the &lt;&gt;
block, variadic class inheritance and variadic constructor and
initializers) with some limitations. The following code is correctly parsed:</p>
@ -517,11 +517,13 @@ public:
const int SIZE = sizeof...(ClassName&lt;int, int&gt;);
</pre></div>
<p>For now however, the <tt>%template</tt> directive only accepts at most the number of
arguments defined in the original template&lt;&gt; block:</p>
<p>
For now however, the <tt>%template</tt> directive only accepts one parameter substitution
for the variable template parameters.
</p>
<div class="code"><pre>
%template(MyVariant1) ClassName&lt;&gt; // ok
%template(MyVariant1) ClassName&lt;&gt; // zero argument not supported
%template(MyVariant2) ClassName&lt;int&gt; // ok
%template(MyVariant3) ClassName&lt;int, int&gt; // too many arguments
</pre></div>

View file

@ -4,9 +4,9 @@
using variadic number of classes.
*/
%module cpp0x_variadic_templates
%warnfilter(507) MultiArgs1;
%warnfilter(507) SizeOf1;
%warnfilter(507) MultiInherit1;
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiArgs;
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) SizeOf;
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiInherit;
////////////////////////
// Variadic templates //
@ -36,7 +36,6 @@ template<typename... Args> struct SizeOf {
};
%}
// TODO
%template (SizeOf1) SizeOf<int, int>;
//////////////////////////
@ -48,7 +47,7 @@ public:
A() {
a = 100;
}
virtual ~A() {}
int a;
};
@ -57,14 +56,22 @@ public:
B() {
b = 200;
}
virtual ~B() {}
int b;
};
template <typename... BaseClasses> class MultiInherit : public BaseClasses... {
public:
MultiInherit(BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
MultiInherit(BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
int InstanceMethod() { return 123; }
static int StaticMethod() { return 456; }
};
%}
// TODO
%template (MultiInherit1) MultiInherit<A,B>;
//%template (MultiInherit0) MultiInherit<>;
%template (MultiInherit1) MultiInherit<A>;
// TODO
%template (MultiInherit2) MultiInherit<A,B>;