Document improved variadic template support
This commit is contained in:
parent
f648e58cb1
commit
cdf9a18603
2 changed files with 48 additions and 11 deletions
|
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
|||
Version 4.2.0 (in progress)
|
||||
===========================
|
||||
|
||||
2022-12-22: wsfulton
|
||||
Complete support for C++11 variadic templates. Support was previously limited
|
||||
to just one template parameter. Now zero or more template parameters are supported.
|
||||
|
||||
2022-12-06: wsfulton
|
||||
#1636 Fix syntax error for misplaced Doxygen comment after struct/class member.
|
||||
Fix syntax error using Doxygen member groups syntax, "///*}", when used after
|
||||
|
|
|
|||
|
|
@ -1125,38 +1125,71 @@ union P {
|
|||
<H3><a name="CPlusPlus11_variadic_templates">7.2.18 Variadic templates</a></H3>
|
||||
|
||||
|
||||
<p>SWIG supports the variadic templates syntax (inside the <>
|
||||
block, variadic class inheritance and variadic constructor and
|
||||
initializers) with some limitations. The following code is correctly parsed:</p>
|
||||
<p>SWIG supports the variadic templates including the <>
|
||||
variadic class inheritance, variadic methods, variadic constructors and
|
||||
initializers. Example:</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
template <typename... BaseClasses> class ClassName : public BaseClasses... {
|
||||
public:
|
||||
ClassName(BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
|
||||
void InstanceMethod(const BaseClasses&... baseClasses) {}
|
||||
};
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
For now however, the <tt>%template</tt> directive only accepts one parameter substitution
|
||||
for the variable template parameters.
|
||||
The <tt>%template</tt> directive works as expected for variable template parameters.
|
||||
</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
%template(MyVariant1) ClassName<> // zero argument not supported yet
|
||||
%template(MyVariant2) ClassName<int> // ok
|
||||
%template(MyVariant3) ClassName<int, int> // too many arguments not supported yet
|
||||
struct A {
|
||||
virtual void amethod();
|
||||
virtual ~A();
|
||||
};
|
||||
struct B {
|
||||
virtual void bmethod();
|
||||
virtual ~B();
|
||||
};
|
||||
%template(ClassName0) ClassName<>
|
||||
%template(ClassName1) ClassName<A>
|
||||
%template(ClassName2) ClassName<A, B>
|
||||
</pre></div>
|
||||
|
||||
<p>Support for the variadic <tt>sizeof()</tt> function is correctly parsed:</p>
|
||||
<p>
|
||||
Example usage from say Python:
|
||||
</p>
|
||||
|
||||
<div class="targetlang"><pre>
|
||||
cn0 = ClassName0()
|
||||
cn0.InstanceMethod()
|
||||
|
||||
a = A()
|
||||
cn1 = ClassName1(a)
|
||||
cn1.amethod()
|
||||
cn1.InstanceMethod(a)
|
||||
|
||||
b = B()
|
||||
cn2 = ClassName2(a, b)
|
||||
cn2.InstanceMethod(a, b)
|
||||
cn2.amethod()
|
||||
cn2.bmethod()
|
||||
</pre></div>
|
||||
|
||||
<p>Support for the variadic <tt>sizeof()</tt> function also works:</p>
|
||||
|
||||
<div class="code"><pre>
|
||||
const int SIZE = sizeof...(ClassName<int, int>);
|
||||
const int SIZE = sizeof...(ClassName<A, B>);
|
||||
</pre></div>
|
||||
|
||||
<p>
|
||||
In the above example <tt>SIZE</tt> is of course wrapped as a constant.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Compatibility note:</b> SWIG-4.2.0 was the first version to fully support variadic templates.
|
||||
SWIG-3.0.0 provided initial support and was limited to only one variadic parameter.
|
||||
</p>
|
||||
|
||||
<H3><a name="CPlusPlus11_new_char_literals">7.2.19 New character literals</a></H3>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue