diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2022-12-22 19:35:20 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2022-12-22 21:23:44 +0000 |
commit | cdf9a18603e298d85edd05a5f44783014cd7336e (patch) | |
tree | 8fb4cb86324ee652edb57c24865b56f7f6a643af /Doc | |
parent | f648e58cb1062984b77946d0ebf9ea2778c933d2 (diff) | |
download | swig-cdf9a18603e298d85edd05a5f44783014cd7336e.tar.gz |
Document improved variadic template support
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/Manual/CPlusPlus11.html | 55 |
1 files changed, 44 insertions, 11 deletions
diff --git a/Doc/Manual/CPlusPlus11.html b/Doc/Manual/CPlusPlus11.html index 50402cefd..6fdc1512a 100644 --- a/Doc/Manual/CPlusPlus11.html +++ b/Doc/Manual/CPlusPlus11.html @@ -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)... {} + 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> +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 is correctly parsed:</p> +<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> |