From cdf9a18603e298d85edd05a5f44783014cd7336e Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 22 Dec 2022 19:35:20 +0000 Subject: [PATCH] Document improved variadic template support --- CHANGES.current | 4 +++ Doc/Manual/CPlusPlus11.html | 55 +++++++++++++++++++++++++++++-------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 6581c4073..adb4053d7 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -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 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 {

7.2.18 Variadic templates

-

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:

+

SWIG supports the variadic templates including the <> +variadic class inheritance, variadic methods, variadic constructors and +initializers. Example:

 template <typename... BaseClasses> class ClassName : public BaseClasses... {
 public:
-  ClassName (BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
+  ClassName(BaseClasses &&... baseClasses) : BaseClasses(baseClasses)... {}
+  void InstanceMethod(const BaseClasses&... baseClasses) {}
 };
 

-For now however, the %template directive only accepts one parameter substitution -for the variable template parameters. +The %template directive works as expected for variable template parameters.

-%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>
 
-

Support for the variadic sizeof() function is correctly parsed:

+

+Example usage from say Python: +

+ +
+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()
+
+ +

Support for the variadic sizeof() function also works:

-const int SIZE = sizeof...(ClassName<int, int>);
+const int SIZE = sizeof...(ClassName<A, B>);
 

In the above example SIZE is of course wrapped as a constant.

+

+Compatibility note: 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. +

+

7.2.19 New character literals