diff options
author | Aethylia <fydrenak@gmail.com> | 2020-11-09 13:14:06 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-09 14:14:06 +0100 |
commit | 53eca459f1d96c710238be95bd3fb048b336f2f3 (patch) | |
tree | 693db1fd9e9c5beedb4d31662b4163107f121111 /doc | |
parent | 3948b40bcd79a3883529608bf4bd156c2e9de5f8 (diff) | |
download | Nim-53eca459f1d96c710238be95bd3fb048b336f2f3.tar.gz |
Added [:T] syntax explanation to generics tutorial. (#15890)
* Added [:T] syntax explanation to generics tutorial. * Update doc/tut2.rst Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com> * Update doc/tut2.rst Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com> * Made second generics example runnable and added test line. * Update doc/tut2.rst * Update doc/tut2.rst * Update doc/tut2.rst Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/tut2.rst | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/tut2.rst b/doc/tut2.rst index 94725a5d8..32faf452c 100644 --- a/doc/tut2.rst +++ b/doc/tut2.rst @@ -534,6 +534,19 @@ iterator or type. As the example shows, generics work with overloading: the best match of ``add`` is used. The built-in ``add`` procedure for sequences is not hidden and is used in the ``preorder`` iterator. +There is a special ``[:T]`` syntax when using generics with the method call syntax: + +.. code-block:: nim + :test: "nim c $1" + proc foo[T](i: T) = + discard + + var i: int + + # i.foo[int]() # Error: expression 'foo(i)' has no type (or is ambiguous) + + i.foo[:int]() # Success + Templates ========= |