From 007a75480aa92156784825a1cf5dd24f97397e0b Mon Sep 17 00:00:00 2001
From: Michael Schaller
-Needless to say, SWIG's template support provides plenty of -opportunities to break the universe. That said, an important final -point is that SWIG does not perform extensive error checking of -templates! Specifically, SWIG does not perform type checking nor -does it check to see if the actual contents of the template -declaration make any sense. Since the C++ compiler will hopefully -check this when it compiles the resulting wrapper file, there is no -practical reason for SWIG to duplicate this functionality (besides, -none of the SWIG developers are masochistic enough to want to -implement this right now). +Needless to say, SWIG's template support provides plenty of opportunities to +break the universe. That said, an important final point is that SWIG does +not perform extensive error checking of templates! Specifically, SWIG does +not perform type checking nor does it check to see if the actual contents of the +template declaration make any sense. Since the C++ compiler checks this when it +compiles the resulting wrapper file, there is no practical reason for SWIG to +duplicate this functionality.
+ ++As SWIG's template support does not perform type checking %template +can be used as early as after a template declaration. You can, and rarely have +to, use %template before the template parameters have been declared. +For example: +
+ +
+template <class T> class OuterTemplateClass {};
+
+// The nested class OuterClass::InnerClass inherits from the template class
+// OuterTemplateClass<OuterClass::InnerStruct> and thus the template needs
+// to be expanded with %template before the OuterClass declaration.
+%template(OuterTemplateClass_OuterClass__InnerStruct)
+ OuterTemplateClass<OuterClass::InnerStruct>
+
+
+// Don't forget to use %feature("flatnested") for OuterClass::InnerStruct and
+// OuterClass::InnerClass if the target language doesn't support nested classes.
+class OuterClass {
+ public:
+ // Forward declarations:
+ struct InnerStruct;
+ class InnerClass;
+};
+
+struct OuterClass::InnerStruct {};
+
+// Expanding the template at this point with %template is too late as the
+// OuterClass::InnerClass declaration is processed inside OuterClass.
+
+class OuterClass::InnerClass : public OuterTemplateClass<InnerStruct> {};
+
+Compatibility Note: The first implementation of template support relied heavily on macro expansion in the preprocessor. Templates have been more tightly integrated into @@ -5000,6 +5034,12 @@ class Bar { +
+If a nested class has to be used as template parameter then the template might +has to be expanded before the top-level class containing the inner class gets +declared. An example can be found in the + Templates section. +
Compatibility Note:
From f25f5cf635396c581507ee932b877bb2c202b584 Mon Sep 17 00:00:00 2001
From: William S Fulton
-If a nested class has to be used as template parameter then the template might
-has to be expanded before the top-level class containing the inner class gets
-declared. An example can be found in the
- Templates section.
+If a nested class, within an outer class, has to be used as a template parameter within the outer class, then the template will
+have to be instantiated with %template before the beginning of the outer class.
+An example can be found in the
+Templates section.