mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
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:
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
|
||||
=========
|
||||
|
||||
Reference in New Issue
Block a user