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>
This commit is contained in:
parent
3948b40bcd
commit
53eca459f1
1 changed files with 13 additions and 0 deletions
13
doc/tut2.rst
13
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
|
||||
=========
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue