Merge branch 'michael-schaller-doc-template-nested'
* michael-schaller-doc-template-nested: Nested class template doc tweaks Updated C++ template documentation with respect to using a nested class as template parameter.
This commit is contained in:
commit
01a6df8aad
1 changed files with 50 additions and 10 deletions
|
|
@ -3614,18 +3614,52 @@ and the second will take two integer arguments.
|
|||
</p>
|
||||
|
||||
<p>
|
||||
Needless to say, SWIG's template support provides plenty of
|
||||
opportunities to break the universe. That said, an important final
|
||||
point is that <b>SWIG does not perform extensive error checking of
|
||||
templates!</b> 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 <b>SWIG does
|
||||
not perform extensive error checking of templates!</b> 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.
|
||||
</p>
|
||||
|
||||
<a name="SWIGPlus_template_nested_class_example"></a>
|
||||
<p>
|
||||
As SWIG's template support does not perform type checking <tt>%template</tt>
|
||||
can be used as early as after a template declaration. You can, and rarely have
|
||||
to, use <tt>%template</tt> before the template parameters have been declared.
|
||||
For example:
|
||||
</p>
|
||||
|
||||
<div class="code">
|
||||
<pre>
|
||||
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> {};
|
||||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<b>Compatibility Note</b>: 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 {
|
|||
</pre>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
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 <tt>%template</tt> before the beginning of the outer class.
|
||||
An example can be found in the
|
||||
<a href="#SWIGPlus_template_nested_class_example">Templates</a> section.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b>Compatibility Note:</b>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue