diff --git a/Doc/Manual/Library.html b/Doc/Manual/Library.html index 6c9e07b63..8939c8df0 100644 --- a/Doc/Manual/Library.html +++ b/Doc/Manual/Library.html @@ -1923,30 +1923,42 @@ Adding the missing %shared_ptr macros will fix this:

9.4.4.3 shared_ptr and templates

+

+The %shared_ptr macro should be used for all the required instantiations +of the template before each of the %template instantiations. +For example, consider number.h containing the following illustrative template: +

+ +
+
+#include <memory>
+
+template<int N> struct Number {
+  int num;
+  Number() : num(N) {}
+  static std::shared_ptr<Number<N>> make() { return std::make_shared<Number<N>>(); }
+};
+
+

-Only the single %shared_ptr declaration should be used for all specializations -of the template before the first template instantiation using the following notation: -%shared_ptr(TemplateName<>). For example: +The SWIG code below shows the required ordering:

 %include <std_shared_ptr.i>
 
-%shared_ptr(Graph<>);  // Declaration of the transparent shared ptr for the Graph template
+%shared_ptr(Number<10>);
+%shared_ptr(Number<42>);
 
 %{
-  #include "graph.h"  // Graph definition (inside the namespace gany)
-  using namespace gany;
+  #include "number.h"
 %}
+%include "number.h"
 
-%include "graph.h"  // Graph declaration (inside the namespace gany)
-using namespace gany;
-
-%template(SGraph) Graph<false>;  // Simple graph
-// Note: the Graph name is redefined in the following line from the template to the specialization (class)
-%template(WGraph) Graph<true>;  // Weighted graph
+%template(Number10) Number<10>;
+%template(Number42) Number<42>;
 
diff --git a/Doc/Manual/SWIG.html b/Doc/Manual/SWIG.html index a81081d9b..d677a223f 100644 --- a/Doc/Manual/SWIG.html +++ b/Doc/Manual/SWIG.html @@ -3306,7 +3306,24 @@ Vector *new_Vector() {

-The %inline directive inserts all of the code that follows +This is the same as writing: +

+ +
+%{
+/* Create a new vector */
+Vector *new_Vector() {
+  return (Vector *) malloc(sizeof(Vector));
+}
+%}
+
+/* Create a new vector */
+Vector *new_Vector() {
+  return (Vector *) malloc(sizeof(Vector));
+}
+
+

+In other words, the %inline directive inserts all of the code that follows verbatim into the header portion of an interface file. The code is then parsed by both the SWIG preprocessor and parser. Thus, the above example creates a new command new_Vector using only one @@ -3314,10 +3331,10 @@ declaration. Since the code inside an %inline %{ ... %} block is given to both the C compiler and SWIG, it is illegal to include any SWIG directives inside a %{ ... %} block.

+

-Note: Any #include directives are omitted inside the -%inline %{ ... %} block unless the -includeall command line -option is supplied.

+Note: The usual SWIG C preprocessor rules apply to code in %apply blocks when SWIG parses this code. For example, as mentioned earlier, SWIG's C Preprocessor does not follow #include directives by default. +

5.6.4 Initialization blocks