%module overload_template #ifdef SWIGLUA // lua only has one numeric type, so most of the overloads shadow each other creating warnings %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) foo; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) maximum; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) specialization; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) overload; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) space::nsoverload; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) fooT; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) barT; #endif %inline %{ int foo() { return 3; } template int foo(T x) { return (int)x; } template T maximum(T a, T b) { return (a > b) ? a : b; } %} %template(foo) foo; %template(foo) foo; %template(maximum) maximum; %template(maximum) maximum; // Mix template overloading with plain function overload // Mix 1 %inline %{ int mix1(const char* msg) { return 101; } template int mix1(T t, const T& tt) { return 102; } template int mix1(T t) { return 103; } %} %template(mix1) mix1; // Mix 2 %inline %{ template int mix2(T t, const T& tt) { return 102; } int mix2(const char* msg) { return 101; } template int mix2(T t) { return 103; } %} %template(mix2) mix2; // Mix 3 %inline %{ template int mix3(T t, const T& tt) { return 102; } template int mix3(T t) { return 103; } int mix3(const char* msg) { return 101; } %} %template(mix3) mix3; // overloaded by number of templated parameters // Combination 1 %inline %{ template int overtparams1(T t) { return 10; } template int overtparams1(T t, U u) { return 20; } %} %template(overtparams1) overtparams1; %template(overtparams1) overtparams1; // Combination 2 %inline %{ template int overtparams2(T t) { return 30; } template int overtparams2(T t, U u) { return 40; } %} %template(overtparams2) overtparams2; // Combination 3 %inline %{ template int overloaded(T t) { return 50; } int overloaded() { return 60; } template int overloaded(T t, U u) { return 70; } %} %template(overloaded) overloaded; // Combination 4 %inline %{ int overloadedagain(const char* msg) { return 80; } template int overloadedagain() { return 90; } template int overloadedagain(T t, U u) { return 100; } %} %template(overloadedagain) overloadedagain; // simple specialization %inline %{ template void xyz() {} template<> void xyz() {} void xyz() {} %} // We can have xyz(); xyz(); xyz(); in C++, but can't have this type of overloading in target language, so we need to do some renaming %template(xyz_double) xyz; %template(xyz_int) xyz; // specializations %inline %{ template int specialization(T t) { return 200; } template int specialization(T t, U u) { return 201; } template<> int specialization(int t) { return 202; } template<> int specialization(double t) { return 203; } template<> int specialization(int t, int u) { return 204; } template<> int specialization(double t, double u) { return 205; } %} %template(specialization) specialization; %template(specialization) specialization; %template(specialization) specialization; %template(specialization) specialization; %template(specialization) specialization; // a bit of everything %inline %{ int overload(const char *c) { return 0; } template int overload(T t) { return 10; } template int overload(T t, const T &tref) { return 20; } template int overload(T t, const char *c) { return 30; } template<> int overload(double t, const char *c) { return 40; } int overload() { return 50; } class Klass {}; %} %template(overload) overload; %template(overload) overload; %template(overload) overload; // everything put in a namespace %inline %{ namespace space { int nsoverload(const char *c) { return 1000; } template int nsoverload(T t) { return 1010; } template int nsoverload(T t, const T &tref) { return 1020; } template int nsoverload(T t, const char *c) { return 1030; } template<> int nsoverload(double t, const char *c) { return 1040; } int nsoverload() { return 1050; } } %} %template(nsoverload) space::nsoverload; %template(nsoverload) space::nsoverload; %template(nsoverload) space::nsoverload; %inline %{ namespace space { template struct Foo { void bar(T t1) { } void bar(T t1, T t2) { } void bar(int a, int b, int c) { } }; struct A { template static void fooT(Y y) { } }; } template struct Bar { void foo(T t1) { } void foo(T t1, T t2) { } void foo(int a, int b, int c) { } template void fooT(Y y) { } }; struct B { template void barT(Y y) { } }; %} %template(Bar_d) Bar; %template(Foo_d) space::Foo; %template(foo) space::A::fooT; %template(foo) space::A::fooT; %template(foo) space::A::fooT; %template(foo) B::barT; %template(foo) B::barT; %template(foo) B::barT;