Instantiation of C++11 variadic function templates
Complete support for C++11 variadic function templates. Support was previously limited to just one template parameter. Now zero or more template parameters are supported in the %template instantiation.
This commit is contained in:
parent
cdc08c9325
commit
2fc0edc4fd
5 changed files with 132 additions and 55 deletions
|
|
@ -78,5 +78,19 @@ void emplace(Args &&... args) noexcept(
|
|||
%}
|
||||
|
||||
%template(emplace) EmplaceContainer::emplace<int,A>;
|
||||
// TODO
|
||||
//%template(emplace) EmplaceContainer::emplace<int,A,B,C>;
|
||||
%template(emplace) EmplaceContainer::emplace<int,A,B>;
|
||||
%template(emplace) EmplaceContainer::emplace<int,A,B,C>;
|
||||
%template(emplace) EmplaceContainer::emplace<int,A,B,C,D>;
|
||||
|
||||
|
||||
// Overloading mix of variadic and non-variadic templates
|
||||
%inline %{
|
||||
template<typename T, typename U> int variadicmix1(T t, U u) { return 10; }
|
||||
template<typename... T> int variadicmix1(T... t) { return 20; }
|
||||
%}
|
||||
|
||||
%template(variadicmix1) variadicmix1<>;
|
||||
%template(variadicmix1) variadicmix1<A>;
|
||||
%template(variadicmix1) variadicmix1<A,B>;
|
||||
%template(variadicmix1) variadicmix1<A,B,C>;
|
||||
%template(variadicmix1) variadicmix1<int, int>;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
from cpp11_variadic_function_templates import *
|
||||
|
||||
ec = EmplaceContainer()
|
||||
ec.emplace(A())
|
||||
ec.emplace(A(), B())
|
||||
ec.emplace(A(), B(), C())
|
||||
ec.emplace(A(), B(), C(), D())
|
||||
|
||||
def check(expected, got):
|
||||
if expected != got:
|
||||
raise RuntimeError("failed: {} != {}".format(expected, got))
|
||||
|
||||
a = A()
|
||||
b = B()
|
||||
c = C()
|
||||
check(variadicmix1(), 20)
|
||||
check(variadicmix1(a), 20)
|
||||
check(variadicmix1(a, b), 10)
|
||||
check(variadicmix1(a, b, c), 20)
|
||||
check(variadicmix1(11, 22), 10)
|
||||
Loading…
Add table
Add a link
Reference in a new issue