Support multiple arguments in variadic templates.
Remove warning SWIGWARN_CPP11_VARIADIC_TEMPLATE which was issued if more than one argument was used for a variadic template. SwigType enhancement: 'v.' now represents a variadic argument.
This commit is contained in:
parent
1e73045da8
commit
67c4c2186c
13 changed files with 465 additions and 66 deletions
|
|
@ -632,10 +632,10 @@ CPP11_TEST_CASES += \
|
|||
cpp11_uniform_initialization \
|
||||
cpp11_unrestricted_unions \
|
||||
cpp11_userdefined_literals \
|
||||
cpp11_variadic_templates \
|
||||
|
||||
# Broken C++11 test cases.
|
||||
CPP11_TEST_BROKEN = \
|
||||
# cpp11_variadic_templates \ # Broken for some languages (such as Java)
|
||||
# cpp11_reference_wrapper \ # No typemaps
|
||||
|
||||
# C++14 test cases.
|
||||
|
|
|
|||
|
|
@ -4,9 +4,21 @@
|
|||
using variadic number of classes.
|
||||
*/
|
||||
%module cpp11_variadic_templates
|
||||
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiArgs;
|
||||
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) SizeOf;
|
||||
%warnfilter(SWIGWARN_CPP11_VARIADIC_TEMPLATE) MultiInherit;
|
||||
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_D_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_PHP_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_RUBY_MULTIPLE_INHERITANCE) MultiInherit;
|
||||
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_D_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_PHP_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_RUBY_MULTIPLE_INHERITANCE) NumerousInherit;
|
||||
%warnfilter(SWIGWARN_JAVA_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_CSHARP_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_D_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_PHP_MULTIPLE_INHERITANCE,
|
||||
SWIGWARN_RUBY_MULTIPLE_INHERITANCE) LotsInherit;
|
||||
|
||||
////////////////////////
|
||||
// Variadic templates //
|
||||
|
|
@ -24,7 +36,6 @@ class MultiArgs<int, std::vector<int>, std::map<std::string, std::vector<int>>>
|
|||
|
||||
%}
|
||||
|
||||
// TODO
|
||||
%template (MultiArgs1) MultiArgs<int, std::vector<int>, std::map<std::string, std::vector<int>>>;
|
||||
|
||||
////////////////////////
|
||||
|
|
@ -36,7 +47,10 @@ template<typename... Args> struct SizeOf {
|
|||
};
|
||||
%}
|
||||
|
||||
%template (SizeOf1) SizeOf<int, int>;
|
||||
%template (SizeOf0) SizeOf<>;
|
||||
%template (SizeOf1) SizeOf<int>;
|
||||
%template (SizeOf2) SizeOf<int, int>;
|
||||
%template (SizeOf3) SizeOf<int, int, int>;
|
||||
|
||||
//////////////////////////
|
||||
// Variadic inheritance //
|
||||
|
|
@ -60,18 +74,67 @@ public:
|
|||
int b;
|
||||
};
|
||||
|
||||
class C {
|
||||
public:
|
||||
C() {
|
||||
c = 300;
|
||||
}
|
||||
virtual ~C() {}
|
||||
int c;
|
||||
};
|
||||
|
||||
class D {
|
||||
public:
|
||||
D() {
|
||||
d = 400;
|
||||
}
|
||||
virtual ~D() {}
|
||||
int d;
|
||||
};
|
||||
|
||||
template <typename... BaseClasses> class MultiInherit : public BaseClasses... {
|
||||
public:
|
||||
MultiInherit(BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
|
||||
void MultiInstanceMethod(BaseClasses&... baseClasses) {}
|
||||
static void MultiStaticMethod(BaseClasses&... baseClasses) {}
|
||||
int InstanceMethod() { return 123; }
|
||||
static int StaticMethod() { return 456; }
|
||||
};
|
||||
%}
|
||||
|
||||
|
||||
// TODO
|
||||
//%template (MultiInherit0) MultiInherit<>;
|
||||
%template (MultiInherit0) MultiInherit<>;
|
||||
%template (MultiInherit1) MultiInherit<A>;
|
||||
// TODO
|
||||
%template (MultiInherit2) MultiInherit<A,B>;
|
||||
%template (MultiInherit3) MultiInherit<A,B,C>;
|
||||
|
||||
%inline %{
|
||||
template <typename... BaseClasses> class NumerousInherit : public BaseClasses... {
|
||||
public:
|
||||
NumerousInherit(int i, BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
|
||||
void NumerousInstanceMethod(int i, BaseClasses&... baseClasses) {}
|
||||
static void NumerousStaticMethod(int i, BaseClasses&... baseClasses) {}
|
||||
int InstanceMethod() { return 123; }
|
||||
static int StaticMethod() { return 456; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template (NumerousInherit0) NumerousInherit<>;
|
||||
%template (NumerousInherit1) NumerousInherit<A>;
|
||||
%template (NumerousInherit2) NumerousInherit<A,B>;
|
||||
%template (NumerousInherit3) NumerousInherit<A,B,C>;
|
||||
|
||||
%inline %{
|
||||
template <typename T, typename... BaseClasses> class LotsInherit : public T, public BaseClasses... {
|
||||
public:
|
||||
LotsInherit(T t, BaseClasses&... baseClasses) : BaseClasses(baseClasses)... {}
|
||||
void LotsInstanceMethod(T t, BaseClasses&... baseClasses) {}
|
||||
static void LotsStaticMethod(T t, BaseClasses&... baseClasses) {}
|
||||
int InstanceMethod() { return 123; }
|
||||
static int StaticMethod() { return 456; }
|
||||
};
|
||||
%}
|
||||
|
||||
%template (LotsInherit1) LotsInherit<A>;
|
||||
%template (LotsInherit2) LotsInherit<A,B>;
|
||||
%template (LotsInherit3) LotsInherit<A,B,C>;
|
||||
%template (LotsInherit4) LotsInherit<A,B,C,D>;
|
||||
|
|
|
|||
152
Examples/test-suite/python/cpp11_variadic_templates_runme.py
Normal file
152
Examples/test-suite/python/cpp11_variadic_templates_runme.py
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
from cpp11_variadic_templates import *
|
||||
|
||||
ma = MultiArgs1()
|
||||
|
||||
# SizeOf testing
|
||||
so0 = SizeOf0()
|
||||
if so0.size != 0:
|
||||
raise RuntimeError("so0.size")
|
||||
so1 = SizeOf1()
|
||||
if so1.size != 1:
|
||||
raise RuntimeError("so1.size")
|
||||
so2 = SizeOf2()
|
||||
if so2.size != 2:
|
||||
raise RuntimeError("so2.size")
|
||||
so3 = SizeOf3()
|
||||
if so3.size != 3:
|
||||
raise RuntimeError("so3.size")
|
||||
|
||||
a = A()
|
||||
b = B()
|
||||
c = C()
|
||||
d = D()
|
||||
|
||||
# MultiInherit0
|
||||
mi0 = MultiInherit0()
|
||||
mi0.MultiInstanceMethod()
|
||||
MultiInherit0.MultiStaticMethod()
|
||||
mi0.InstanceMethod()
|
||||
MultiInherit0.StaticMethod()
|
||||
|
||||
# MultiInherit1
|
||||
mi1 = MultiInherit1(a)
|
||||
if mi1.a != 100:
|
||||
raise RuntimeError("fail mi1.a")
|
||||
mi1.MultiInstanceMethod(a)
|
||||
MultiInherit1.MultiStaticMethod(a)
|
||||
mi1.InstanceMethod()
|
||||
MultiInherit1.StaticMethod()
|
||||
|
||||
# MultiInherit2
|
||||
mi2 = MultiInherit2(a, b)
|
||||
if mi2.a != 100:
|
||||
raise RuntimeError("fail mi2.a")
|
||||
if mi2.b != 200:
|
||||
raise RuntimeError("fail mi2.b")
|
||||
mi2.MultiInstanceMethod(a, b)
|
||||
MultiInherit2.MultiStaticMethod(a, b)
|
||||
mi2.InstanceMethod()
|
||||
MultiInherit2.StaticMethod()
|
||||
|
||||
# MultiInherit3
|
||||
mi3 = MultiInherit3(a, b, c)
|
||||
if mi3.a != 100:
|
||||
raise RuntimeError("fail mi3.a")
|
||||
if mi3.b != 200:
|
||||
raise RuntimeError("fail mi3.b")
|
||||
if mi3.c != 300:
|
||||
raise RuntimeError("fail mi3.c")
|
||||
mi3.MultiInstanceMethod(a, b, c)
|
||||
MultiInherit3.MultiStaticMethod(a, b, c)
|
||||
mi3.InstanceMethod()
|
||||
MultiInherit3.StaticMethod()
|
||||
|
||||
# NumerousInherit0
|
||||
num = 123
|
||||
ni0 = NumerousInherit0(num)
|
||||
ni0.NumerousInstanceMethod(num)
|
||||
NumerousInherit0.NumerousStaticMethod(num)
|
||||
ni0.InstanceMethod()
|
||||
NumerousInherit0.StaticMethod()
|
||||
|
||||
# NumerousInherit1
|
||||
ni1 = NumerousInherit1(num, a)
|
||||
if ni1.a != 100:
|
||||
raise RuntimeError("fail ni1.a")
|
||||
ni1.NumerousInstanceMethod(num, a)
|
||||
NumerousInherit1.NumerousStaticMethod(num, a)
|
||||
ni1.InstanceMethod()
|
||||
NumerousInherit1.StaticMethod()
|
||||
|
||||
# NumerousInherit2
|
||||
ni2 = NumerousInherit2(num, a, b)
|
||||
if ni2.a != 100:
|
||||
raise RuntimeError("fail ni2.a")
|
||||
if ni2.b != 200:
|
||||
raise RuntimeError("fail ni2.b")
|
||||
ni2.NumerousInstanceMethod(num, a, b)
|
||||
NumerousInherit2.NumerousStaticMethod(num, a, b)
|
||||
ni2.InstanceMethod()
|
||||
NumerousInherit2.StaticMethod()
|
||||
|
||||
# NumerousInherit3
|
||||
ni3 = NumerousInherit3(num, a, b, c)
|
||||
if ni3.a != 100:
|
||||
raise RuntimeError("fail ni3.a")
|
||||
if ni3.b != 200:
|
||||
raise RuntimeError("fail ni3.b")
|
||||
if ni3.c != 300:
|
||||
raise RuntimeError("fail ni3.c")
|
||||
ni3.NumerousInstanceMethod(num, a, b, c)
|
||||
NumerousInherit3.NumerousStaticMethod(num, a, b, c)
|
||||
ni3.InstanceMethod()
|
||||
NumerousInherit3.StaticMethod()
|
||||
|
||||
LotsInherit1
|
||||
lots1 = LotsInherit1(a)
|
||||
if lots1.a != 100:
|
||||
raise RuntimeError("fail lots1.a")
|
||||
lots1.LotsInstanceMethod(a)
|
||||
LotsInherit1.LotsStaticMethod(a)
|
||||
lots1.InstanceMethod()
|
||||
LotsInherit1.StaticMethod()
|
||||
|
||||
# LotsInherit2
|
||||
lots2 = LotsInherit2(a, b)
|
||||
if lots2.a != 100:
|
||||
raise RuntimeError("fail lots2.a")
|
||||
if lots2.b != 200:
|
||||
raise RuntimeError("fail lots2.b")
|
||||
lots2.LotsInstanceMethod(a, b)
|
||||
LotsInherit2.LotsStaticMethod(a, b)
|
||||
lots2.InstanceMethod()
|
||||
LotsInherit2.StaticMethod()
|
||||
|
||||
# LotsInherit3
|
||||
lots3 = LotsInherit3(a, b, c)
|
||||
if lots3.a != 100:
|
||||
raise RuntimeError("fail lots3.a")
|
||||
if lots3.b != 200:
|
||||
raise RuntimeError("fail lots3.b")
|
||||
if lots3.c != 300:
|
||||
raise RuntimeError("fail lots3.c")
|
||||
lots3.LotsInstanceMethod(a, b, c)
|
||||
LotsInherit3.LotsStaticMethod(a, b, c)
|
||||
lots3.InstanceMethod()
|
||||
LotsInherit3.StaticMethod()
|
||||
|
||||
# LotsInherit4
|
||||
lots4 = LotsInherit4(a, b, c, d)
|
||||
if lots4.a != 100:
|
||||
raise RuntimeError("fail lots4.a")
|
||||
if lots4.b != 200:
|
||||
raise RuntimeError("fail lots4.b")
|
||||
if lots4.c != 300:
|
||||
raise RuntimeError("fail lots4.c")
|
||||
if lots4.d != 400:
|
||||
raise RuntimeError("fail lots4.c")
|
||||
lots4.LotsInstanceMethod(a, b, c, d)
|
||||
LotsInherit4.LotsStaticMethod(a, b, c, d)
|
||||
lots4.InstanceMethod()
|
||||
LotsInherit4.StaticMethod()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue