From a9397c3b49ae4b6be44eb5d59fe49edf2309f773 Mon Sep 17 00:00:00 2001 From: Simon Marchetto Date: Wed, 2 Apr 2014 18:05:26 +0200 Subject: [PATCH] scilab: rewrite doc on templates --- Doc/Manual/Scilab.html | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Doc/Manual/Scilab.html b/Doc/Manual/Scilab.html index 9b321f2e3..f98dc387d 100644 --- a/Doc/Manual/Scilab.html +++ b/Doc/Manual/Scilab.html @@ -960,6 +960,63 @@ But we can use either use the get_perimeter() function of the parent cl

37.3.10 C++ Templates

+

+As in other languages, function and class templates are supported in SWIG Scilab. +

+ +

+You have to tell SWIG to create wrappers for a particular +template instantiation. The %template directive is used for that purpose. +For example: +

+ +
+%module example
+
+template<class T1, class T2, class T3>
+struct triplet {
+  T1 first;
+  T2 second;
+  T3 third;
+  triplet(const T1& a, const T2& b, const T3& c) {
+    third = a; second = b; third = c;
+  }
+};
+
+%template(IntTriplet) triplet<int,int,int>;
+
+ +

+Then in Scilab: +

+ +
+
+-->t = new_IntTriplet(3, 4, 1);
+
+-->IntTriplet_first_get(t)
+ ans  =
+
+  3.
+
+-->IntTriplet_second_get(t)
+ ans  =
+
+  4.
+
+-->IntTriplet_third_get(t)
+ ans  =
+
+  1.
+
+-->delete_IntTriplet(t);
+
+
+ +

+More details on template support can be found in the SWIG C++ documentation. +

+

Templates are supported. See the SWIG general documentation on how templates are interfaced in SWIG.
An example of templates can be found in Examples/scilab/templates.