%module template_templated_constructors %inline %{ namespace ConstructSpace { class TConstructor1 { public: template TConstructor1(T val) {} ~TConstructor1() {} }; class TConstructor2 { public: TConstructor2() {} template TConstructor2(T val) {} ~TConstructor2() {} }; class TConstructor3 { public: // No implicit default constructor available template TConstructor3(T val) {} ~TConstructor3() {} }; class TConstructor4 { public: // No constructors available from wrappers when there is no %template to instantiate templated constructor template TConstructor4() {} ~TConstructor4() {} }; template class TClass1 { public: template TClass1(Y t) {} }; template class TClass2 { public: TClass2() {} template TClass2(Y t) {} }; } %} %extend ConstructSpace::TConstructor1 { %template(TConstructor1) TConstructor1; } %template(TConstructor2) ConstructSpace::TConstructor2::TConstructor2; %template(TClass1Int) ConstructSpace::TClass1; %extend ConstructSpace::TClass1 { %template(TClass1Int) TClass1; } %template(TClass2Int) ConstructSpace::TClass2; %extend ConstructSpace::TClass2 { %template(TClass2Int) TClass2; } %inline %{ // Simple version of std::pair namespace Standard { template struct Pair { typedef T first_type; typedef U second_type; Pair() {} Pair(const T& first, const U& second) {} Pair(const Pair& other) {} template Pair(const Pair< U1, U2 > &otherone) {} }; } %} %include namespace Standard { %template(StringPair) Pair; %template(ShortPair) Pair; %template(IntPair) Pair; %template(DoublePair) Pair; %extend Pair { // Templated constructor which uses 'correct' name of the containing class (IntPair) %template(IntPair) Pair; // Templated constructors that behave differently in different languages as the template name // does not match IntPair, the instantiated name for Pair. // Some languages wrap as a factory style function (Python), // others ignore the name and wrap as regular constructor (Java). %template(Pair) Pair; %template(MakeStringPair) Pair; } }