summary refs log tree commit diff stats
path: root/doc/nimc.txt
diff options
context:
space:
mode:
Diffstat (limited to 'doc/nimc.txt')
-rw-r--r--doc/nimc.txt37
1 files changed, 35 insertions, 2 deletions
diff --git a/doc/nimc.txt b/doc/nimc.txt
index c6b0b5255..cfbccc479 100644
--- a/doc/nimc.txt
+++ b/doc/nimc.txt
@@ -506,7 +506,7 @@ For example:
 .. code-block:: nim
 
   type Input {.importcpp: "System::Input".} = object
-  proc getSubsystem*[T](): ptr T {.importcpp: "SystemManager::getSubsystem<'*0>()".}
+  proc getSubsystem*[T](): ptr T {.importcpp: "SystemManager::getSubsystem<'*0>()", nodecl.}
 
   let x: ptr Input = getSubsystem[Input]()
 
@@ -545,6 +545,20 @@ instead:
   let x = newFoo(3, 4)
 
 
+Wrapping constructors
+~~~~~~~~~~~~~~~~~~~~~
+
+Sometimes a C++ class has a private copy constructor and so code like
+``Class c = Class(1,2);`` must not be generated but instead ``Class c(1,2);``.
+For this purpose the Nim proc that wraps a C++ constructor needs to be
+annotated with the `constructor`:idx: pragma. This pragma also helps to generate
+faster C++ code since construction then doesn't invoke the copy constructor:
+
+.. code-block:: nim
+  # a better constructor of 'Foo':
+  proc constructFoo(a, b: cint): Foo {.importcpp: "Foo(@)", constructor.}
+
+
 Wrapping destructors
 ~~~~~~~~~~~~~~~~~~~~
 
@@ -582,6 +596,25 @@ Produces:
   x[6] = 91.4;
 
 
+- If more precise control is needed, the apostrophe ``'`` can be used in the
+  supplied pattern to denote the concrete type parameters of the generic type.
+  See the usage of the apostrophe operator in proc patterns for more details.
+
+.. code-block:: nim
+
+  type
+    VectorIterator {.importcpp: "std::vector<'0>::iterator".} [T] = object
+
+  var x: VectorIterator[cint]
+
+
+Produces:
+
+.. code-block:: C
+  
+  std::vector<int>::iterator x;
+
+
 ImportObjC pragma
 -----------------
 Similar to the `importc pragma for C <manual.html#importc-pragma>`_, the
@@ -608,7 +641,7 @@ allows *sloppy* interfacing with libraries written in Objective C:
 
   - (void)greet:(long)x y:(long)dummy
   {
-	  printf("Hello, World!\n");
+    printf("Hello, World!\n");
   }
   @end