1 %module template_default_arg
3 %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Hello; /* Ruby, wrong class name */
5 // lua only has one numeric type, so most of the overloads shadow each other creating warnings
6 %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) X;
7 %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) Z;
8 %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) meth;
15 typedef unsigned int size_type;
16 Foo(size_type n = size_type(0) ) { }
19 int foob(Foo<int> h = Foo<int>()) {return 1; }
24 typedef unsigned int size_type;
27 // Hello(size_type n = Hello<T>::size_type(0) ) { }
30 Hello(size_type n = size_type(0) ) { }
32 enum Hi { hi, hello };
34 void foo(Hi h = hi) { }
37 template <typename T> struct X {
38 X(const T& t = T()) {}
39 X(double a, const T& t = T(0)) {}
40 T meth(double a, const T& t = T(0)) { return t; }
41 const T& meth(const T& t = T(0)) { return t; }
44 template <typename TT> class Y : private X<TT> {
46 // test using on templated class with default args in the method
50 template <int V> struct Z
54 Z(double a, int t = V){}
60 %template(Foo_int) Foo<int>;
61 %template(Hello_int) Hello<int>;
62 %template(X_int) X<int>;
63 %template(X_longlong) X<long long>;
64 %template(X_unsigned) X<unsigned>;
65 %template(Y_unsigned) Y<unsigned>;
67 %template(X_hello_unsigned) X<Hello<int> >;
68 %template(Y_hello_unsigned) Y<Hello<int> >;
69 %template(X_Foo_Foo_int) X<Foo<Foo<int> > >;
71 %template(Foo_Z_8) Foo<Z<8> >;
72 %template(X_Foo_Z_8) X<Foo<Z<8> > >;
76 struct Bar : Hello<int>
78 Bar(size_type n) : Hello<int>(n)
86 // Templated functions
88 // Templated methods which are overloaded and have default args, and %template which
89 // uses the same name as the C++ functions and overload on the template parameters and
90 // specialization thrown in too. Wow, SWIG can handle this insane stuff!
91 template<typename T, typename U> int ott(T t = 0, const U& u = U()) { return 10; }
92 template<typename T, typename U> int ott(const char *msg, T t = 0, const U& u = U()) { return 20; }
93 int ott(Foo<int>) { return 30; }
94 template<typename T> int ott(Hello<int> h, T t = 0) { return 40; }
95 template<> int ott<int>(Hello<int> h, int t) { return 50; }
96 template<> int ott(Hello<int> h, double t) { return 60; }
99 %template(ott) ott<int, int>;
100 %template(ott) ott<double>;
101 %template(ottint) ott<int>; // default arg requires a rename
102 %template(ottstring) ott<const char *>; // default arg requires a rename
105 // Above test in namespaces
107 namespace OuterSpace {
108 namespace InnerSpace {
109 // Templated methods which are overloaded and have default args, and %template which
110 // uses the same name as the C++ functions and overload on the template parameters and
111 // specialization thrown in too. Wow, SWIG can handle this insane stuff!
112 template<typename T, typename U> int nsott(T t = 0, const U& u = U()) { return 110; }
113 template<typename T, typename U> int nsott(const char *msg, T t = 0, const U& u = U()) { return 120; }
114 int nsott(Foo<int>) { return 130; }
115 template<typename T> int nsott(Hello<int> h, T t = 0) { return 140; }
116 template<> int nsott<int>(Hello<int> h, int t) { return 150; }
117 template<> int nsott(Hello<int> h, double t) { return 160; }
122 %template(nsott) OuterSpace::InnerSpace::nsott<int, int>;
123 %template(nsott) OuterSpace::InnerSpace::nsott<double>;
124 %template(nsottint) OuterSpace::InnerSpace::nsott<int>; // default arg requires a rename
125 %template(nsottstring) OuterSpace::InnerSpace::nsott<const char *>; // default arg requires a rename