%module template_default_arg %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Hello; /* Ruby, wrong class name */ #ifdef SWIGLUA // lua only has one numeric type, so most of the overloads shadow each other creating warnings %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) X; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Z; %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) meth; #endif %inline %{ template struct Foo { typedef unsigned int size_type; Foo(size_type n = size_type(0) ) { } }; int foob(Foo h = Foo()) {return 1; } template struct Hello { typedef unsigned int size_type; // This works // Hello(size_type n = Hello::size_type(0) ) { } // This doesn't Hello(size_type n = size_type(0) ) { } enum Hi { hi, hello }; void foo(Hi h = hi) { } }; template struct X { X(const T& t = T()) {} X(double a, const T& t = T(0)) {} T meth(double a, const T& t = T(0)) { return t; } const T& meth(const T& t = T(0)) { static T tt; tt = t; return tt; } }; template class Y : private X { public: // test using on templated class with default args in the method using X::meth; }; template struct Z { Z(int t = V) {} // and also: Z(double a, int t = V){} }; %} %template(Foo_int) Foo; %template(Hello_int) Hello; %template(X_int) X; %template(X_longlong) X; %template(X_unsigned) X; %template(Y_unsigned) Y; %template(X_hello_unsigned) X >; %template(Y_hello_unsigned) Y >; %template(X_Foo_Foo_int) X > >; %template(Z_8) Z<8>; %template(Foo_Z_8) Foo >; %template(X_Foo_Z_8) X > >; %inline %{ struct Bar : Hello { Bar(size_type n) : Hello(n) { } }; %} // Templated functions %inline %{ // Templated methods which are overloaded and have default args, and %template which // uses the same name as the C++ functions and overload on the template parameters and // specialization thrown in too. Wow, SWIG can handle this insane stuff! template int ott(T t = 0, const U& u = U()) { return 10; } template int ott(const char *msg, T t = 0, const U& u = U()) { return 20; } int ott(Foo) { return 30; } template int ott(Hello h, T t = 0) { return 40; } template<> int ott(Hello h, int t) { return 50; } template<> int ott(Hello h, double t) { return 60; } %} %template(ott) ott; %template(ott) ott; %template(ottint) ott; // default arg requires a rename %template(ottstring) ott; // default arg requires a rename // Above test in namespaces %inline %{ namespace OuterSpace { namespace InnerSpace { // Templated methods which are overloaded and have default args, and %template which // uses the same name as the C++ functions and overload on the template parameters and // specialization thrown in too. Wow, SWIG can handle this insane stuff! template int nsott(T t = 0, const U& u = U()) { return 110; } template int nsott(const char *msg, T t = 0, const U& u = U()) { return 120; } int nsott(Foo) { return 130; } template int nsott(Hello h, T t = 0) { return 140; } template<> int nsott(Hello h, int t) { return 150; } template<> int nsott(Hello h, double t) { return 160; } } } %} %template(nsott) OuterSpace::InnerSpace::nsott; %template(nsott) OuterSpace::InnerSpace::nsott; %template(nsottint) OuterSpace::InnerSpace::nsott; // default arg requires a rename %template(nsottstring) OuterSpace::InnerSpace::nsott; // default arg requires a rename