typetraits.html 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <!-- This file is generated by Nim. -->
  4. <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <title>std/typetraits</title>
  9. <!-- Google fonts -->
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
  11. <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
  12. <!-- Favicon -->
  13. <link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
  14. <link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
  15. <!-- CSS -->
  16. <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
  17. <!-- JS -->
  18. <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
  19. </head>
  20. <body>
  21. <div class="document" id="documentId">
  22. <div class="container">
  23. <h1 class="title">std/typetraits</h1>
  24. <div class="row">
  25. <div class="three columns">
  26. <div class="theme-select-wrapper">
  27. <label for="theme-select">Theme:&nbsp;</label>
  28. <select id="theme-select" onchange="setTheme(this.value)">
  29. <option value="auto">🌗 Match OS</option>
  30. <option value="dark">🌑 Dark</option>
  31. <option value="light">🌕 Light</option>
  32. </select>
  33. </div>
  34. <div id="global-links">
  35. <ul class="simple-boot">
  36. <li><a href="manual.html">Manual</a></li>
  37. <li><a href="lib.html">Standard library</a></li>
  38. <li> <a id="indexLink" href="theindex.html">Index</a></li>
  39. <li><a href="compiler/theindex.html">Compiler docs</a></li>
  40. <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
  41. <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
  42. </ul>
  43. </div>
  44. <div id="searchInputDiv">
  45. Search: <input type="search" id="searchInput"
  46. oninput="search()" />
  47. </div>
  48. <ul class="simple simple-toc" id="toc-list">
  49. <li>
  50. <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
  51. </li>
  52. <li>
  53. <details open>
  54. <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
  55. <ul class="simple simple-toc-section">
  56. <li><a class="reference" href="#HoleyEnum" title="HoleyEnum = (not Ordinal) and enum">HoleyEnum</a></li>
  57. <li><a class="reference" href="#OrdinalEnum" title="OrdinalEnum = Ordinal and enum">OrdinalEnum</a></li>
  58. <li><a class="reference" href="#StaticParam" title="StaticParam[value] = object">StaticParam</a></li>
  59. </ul>
  60. </details>
  61. </li>
  62. <li>
  63. <details open>
  64. <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
  65. <ul class="simple simple-toc-section">
  66. <ul class="simple nested-toc-section">arity
  67. <li><a class="reference" href="#arity%2Ctypedesc" title="arity(t: typedesc): int">arity(t: typedesc): int</a></li>
  68. </ul>
  69. <ul class="simple nested-toc-section">distinctBase
  70. <li><a class="reference" href="#distinctBase%2Ctypedesc%2Cstaticbool" title="distinctBase(T: typedesc; recursive: static bool = true): typedesc">distinctBase(T: typedesc; recursive: static bool = true): typedesc</a></li>
  71. </ul>
  72. <ul class="simple nested-toc-section">genericHead
  73. <li><a class="reference" href="#genericHead%2Ctypedesc" title="genericHead(t: typedesc): typedesc">genericHead(t: typedesc): typedesc</a></li>
  74. </ul>
  75. <ul class="simple nested-toc-section">hasClosure
  76. <li><a class="reference" href="#hasClosure%2CNimNode" title="hasClosure(fn: NimNode): bool">hasClosure(fn: NimNode): bool</a></li>
  77. </ul>
  78. <ul class="simple nested-toc-section">hasDefaultValue
  79. <li><a class="reference" href="#hasDefaultValue%2Ctypedesc" title="hasDefaultValue(t: typedesc): bool">hasDefaultValue(t: typedesc): bool</a></li>
  80. </ul>
  81. <ul class="simple nested-toc-section">isNamedTuple
  82. <li><a class="reference" href="#isNamedTuple%2Ctypedesc" title="isNamedTuple(T: typedesc): bool">isNamedTuple(T: typedesc): bool</a></li>
  83. </ul>
  84. <ul class="simple nested-toc-section">name
  85. <li><a class="reference" href="#name%2Ctypedesc" title="name(t: typedesc): string">name(t: typedesc): string</a></li>
  86. </ul>
  87. <ul class="simple nested-toc-section">rangeBase
  88. <li><a class="reference" href="#rangeBase%2Ctypedesc%5Brange%5D" title="rangeBase(T: typedesc[range]): typedesc">rangeBase(T: typedesc[range]): typedesc</a></li>
  89. </ul>
  90. <ul class="simple nested-toc-section">stripGenericParams
  91. <li><a class="reference" href="#stripGenericParams%2Ctypedesc" title="stripGenericParams(t: typedesc): typedesc">stripGenericParams(t: typedesc): typedesc</a></li>
  92. </ul>
  93. <ul class="simple nested-toc-section">supportsCopyMem
  94. <li><a class="reference" href="#supportsCopyMem%2Ctypedesc" title="supportsCopyMem(t: typedesc): bool">supportsCopyMem(t: typedesc): bool</a></li>
  95. </ul>
  96. <ul class="simple nested-toc-section">tupleLen
  97. <li><a class="reference" href="#tupleLen%2Ctypedesc%5B%5D" title="tupleLen(T: typedesc[tuple]): int">tupleLen(T: typedesc[tuple]): int</a></li>
  98. </ul>
  99. </ul>
  100. </details>
  101. </li>
  102. <li>
  103. <details open>
  104. <summary><a class="reference reference-toplevel" href="#17" id="67">Macros</a></summary>
  105. <ul class="simple simple-toc-section">
  106. <ul class="simple nested-toc-section">enumLen
  107. <li><a class="reference" href="#enumLen.m%2Ctypedesc%5B%5D" title="enumLen(T: typedesc[enum]): int">enumLen(T: typedesc[enum]): int</a></li>
  108. </ul>
  109. </ul>
  110. </details>
  111. </li>
  112. <li>
  113. <details open>
  114. <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
  115. <ul class="simple simple-toc-section">
  116. <ul class="simple nested-toc-section">distinctBase
  117. <li><a class="reference" href="#distinctBase.t%2CT%2Cstaticbool" title="distinctBase[T](a: T; recursive: static bool = true): untyped">distinctBase[T](a: T; recursive: static bool = true): untyped</a></li>
  118. </ul>
  119. <ul class="simple nested-toc-section">elementType
  120. <li><a class="reference" href="#elementType.t%2Cuntyped" title="elementType(a: untyped): typedesc">elementType(a: untyped): typedesc</a></li>
  121. </ul>
  122. <ul class="simple nested-toc-section">genericParams
  123. <li><a class="reference" href="#genericParams.t%2Ctypedesc" title="genericParams(T: typedesc): untyped">genericParams(T: typedesc): untyped</a></li>
  124. </ul>
  125. <ul class="simple nested-toc-section">get
  126. <li><a class="reference" href="#get.t%2Ctypedesc%5B%5D%2Cstaticint" title="get(T: typedesc[tuple]; i: static int): untyped">get(T: typedesc[tuple]; i: static int): untyped</a></li>
  127. </ul>
  128. <ul class="simple nested-toc-section">pointerBase
  129. <li><a class="reference" href="#pointerBase.t%2Ctypedesc%5B%5D" title="pointerBase[T](_: typedesc[ptr T | ref T]): typedesc">pointerBase[T](_: typedesc[ptr T | ref T]): typedesc</a></li>
  130. </ul>
  131. <ul class="simple nested-toc-section">rangeBase
  132. <li><a class="reference" href="#rangeBase.t%2CT" title="rangeBase[T: range](a: T): untyped">rangeBase[T: range](a: T): untyped</a></li>
  133. </ul>
  134. <ul class="simple nested-toc-section">toSigned
  135. <li><a class="reference" href="#toSigned.t%2Ctypedesc%5B%5D" title="toSigned(T: typedesc[SomeInteger and not range]): untyped">toSigned(T: typedesc[SomeInteger and not range]): untyped</a></li>
  136. </ul>
  137. <ul class="simple nested-toc-section">toUnsigned
  138. <li><a class="reference" href="#toUnsigned.t%2Ctypedesc%5B%5D" title="toUnsigned(T: typedesc[SomeInteger and not range]): untyped">toUnsigned(T: typedesc[SomeInteger and not range]): untyped</a></li>
  139. </ul>
  140. <ul class="simple nested-toc-section">tupleLen
  141. <li><a class="reference" href="#tupleLen.t" title="tupleLen(t: tuple): int">tupleLen(t: tuple): int</a></li>
  142. </ul>
  143. </ul>
  144. </details>
  145. </li>
  146. </ul>
  147. </div>
  148. <div class="nine columns" id="content">
  149. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L1" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  150. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  151. <div id="tocRoot"></div>
  152. <p class="module-desc"><p>This module defines compile-time reflection procs for working with types.</p>
  153. <p>Unstable API.</p>
  154. <p><strong class="examples_text">Example:</strong></p>
  155. <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">typetraits</span>
  156. <span class="Keyword">type</span> <span class="Identifier">A</span> <span class="Operator">=</span> <span class="Keyword">enum</span> <span class="Identifier">a0</span> <span class="Operator">=</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">a1</span> <span class="Operator">=</span> <span class="DecNumber">4</span><span class="Punctuation">,</span> <span class="Identifier">a2</span>
  157. <span class="Keyword">type</span> <span class="Identifier">B</span> <span class="Operator">=</span> <span class="Keyword">enum</span> <span class="Identifier">b0</span> <span class="Operator">=</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">b1</span><span class="Punctuation">,</span> <span class="Identifier">b2</span>
  158. <span class="Identifier">assert</span> <span class="Identifier">A</span> <span class="Keyword">is</span> <span class="Keyword">enum</span>
  159. <span class="Identifier">assert</span> <span class="Identifier">A</span> <span class="Keyword">is</span> <span class="Identifier">HoleyEnum</span>
  160. <span class="Identifier">assert</span> <span class="Identifier">A</span> <span class="Keyword">isnot</span> <span class="Identifier">OrdinalEnum</span>
  161. <span class="Identifier">assert</span> <span class="Identifier">B</span> <span class="Keyword">isnot</span> <span class="Identifier">HoleyEnum</span>
  162. <span class="Identifier">assert</span> <span class="Identifier">B</span> <span class="Keyword">is</span> <span class="Identifier">OrdinalEnum</span>
  163. <span class="Identifier">assert</span> <span class="Identifier">int</span> <span class="Keyword">isnot</span> <span class="Identifier">HoleyEnum</span>
  164. <span class="Keyword">type</span> <span class="Identifier">C</span><span class="Punctuation">[</span><span class="Identifier">T</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Keyword">enum</span> <span class="Identifier">h0</span> <span class="Operator">=</span> <span class="DecNumber">2</span><span class="Punctuation">,</span> <span class="Identifier">h1</span> <span class="Operator">=</span> <span class="DecNumber">4</span>
  165. <span class="Identifier">assert</span> <span class="Identifier">C</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">]</span> <span class="Keyword">is</span> <span class="Identifier">HoleyEnum</span></pre></p>
  166. <div class="section" id="6">
  167. <h1><a class="toc-backref" href="#6">Imports</a></h1>
  168. <dl class="item">
  169. <a class="reference external" href="since.html">since</a>, <a class="reference external" href="assertions.html">assertions</a>, <a class="reference external" href="macros.html">macros</a>
  170. </dl>
  171. </div>
  172. <div class="section" id="7">
  173. <h1><a class="toc-backref" href="#7">Types</a></h1>
  174. <dl class="item">
  175. <div id="HoleyEnum">
  176. <dt><pre><a href="typetraits.html#HoleyEnum"><span class="Identifier">HoleyEnum</span></a> <span class="Other">=</span> <span class="Other">(</span><span class="Keyword">not</span> <a href="system.html#Ordinal"><span class="Identifier">Ordinal</span></a><span class="Other">)</span> <span class="Keyword">and</span> <span class="Keyword">enum</span></pre></dt>
  177. <dd>
  178. Enum with holes.
  179. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L22" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  180. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L22" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  181. </dd>
  182. </div>
  183. <div id="OrdinalEnum">
  184. <dt><pre><a href="typetraits.html#OrdinalEnum"><span class="Identifier">OrdinalEnum</span></a> <span class="Other">=</span> <a href="system.html#Ordinal"><span class="Identifier">Ordinal</span></a> <span class="Keyword">and</span> <span class="Keyword">enum</span></pre></dt>
  185. <dd>
  186. Enum without holes.
  187. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L23" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  188. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L23" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  189. </dd>
  190. </div>
  191. <div id="StaticParam">
  192. <dt><pre><a href="typetraits.html#StaticParam"><span class="Identifier">StaticParam</span></a><span class="Other">[</span><span class="Identifier">value</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span></pre></dt>
  193. <dd>
  194. Used to wrap a static value in <a class="reference external" href="#genericParams.t,typedesc">genericParams</a>.
  195. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L223" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  196. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L223" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  197. </dd>
  198. </div>
  199. </dl>
  200. </div>
  201. <div class="section" id="12">
  202. <h1><a class="toc-backref" href="#12">Procs</a></h1>
  203. <dl class="item">
  204. <div id="arity-procs-all">
  205. <div id="arity,typedesc">
  206. <dt><pre><span class="Keyword">proc</span> <a href="#arity%2Ctypedesc"><span class="Identifier">arity</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  207. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  208. <dd>
  209. Returns the arity of <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>. This is the number of &quot;type&quot; components or the number of generic parameters a given type <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> has.
  210. <p><strong class="examples_text">Example:</strong></p>
  211. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">arity</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
  212. <span class="Identifier">doAssert</span> <span class="Identifier">arity</span><span class="Punctuation">(</span><span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
  213. <span class="Identifier">doAssert</span> <span class="Identifier">arity</span><span class="Punctuation">(</span><span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
  214. <span class="Identifier">doAssert</span> <span class="Identifier">arity</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">float</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span></pre>
  215. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L45" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  216. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L45" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  217. </dd>
  218. </div>
  219. </div>
  220. <div id="distinctBase-procs-all">
  221. <div id="distinctBase,typedesc,staticbool">
  222. <dt><pre><span class="Keyword">proc</span> <a href="#distinctBase%2Ctypedesc%2Cstaticbool"><span class="Identifier">distinctBase</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">;</span> <span class="Identifier">recursive</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">bool</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a> {.
  223. <span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  224. <dd>
  225. <p>Returns the base type for distinct types, or the type itself otherwise. If <tt class="docutils literal"><span class="pre"><span class="Identifier">recursive</span></span></tt> is false, only the immediate distinct base will be returned.</p>
  226. <p><strong>See also:</strong></p>
  227. <ul class="simple"><li><a class="reference external" href="#distinctBase.t,T,static[bool]">distinctBase template</a></li>
  228. </ul>
  229. <p><strong class="examples_text">Example:</strong></p>
  230. <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">MyInt</span> <span class="Operator">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int</span>
  231. <span class="Keyword">type</span> <span class="Identifier">MyOtherInt</span> <span class="Operator">=</span> <span class="Keyword">distinct</span> <span class="Identifier">MyInt</span>
  232. <span class="Identifier">doAssert</span> <span class="Identifier">distinctBase</span><span class="Punctuation">(</span><span class="Identifier">MyInt</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span>
  233. <span class="Identifier">doAssert</span> <span class="Identifier">distinctBase</span><span class="Punctuation">(</span><span class="Identifier">MyOtherInt</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span>
  234. <span class="Identifier">doAssert</span> <span class="Identifier">distinctBase</span><span class="Punctuation">(</span><span class="Identifier">MyOtherInt</span><span class="Punctuation">,</span> <span class="Identifier">false</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">MyInt</span>
  235. <span class="Identifier">doAssert</span> <span class="Identifier">distinctBase</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span></pre>
  236. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L167" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  237. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L167" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  238. </dd>
  239. </div>
  240. </div>
  241. <div id="genericHead-procs-all">
  242. <div id="genericHead,typedesc">
  243. <dt><pre><span class="Keyword">proc</span> <a href="#genericHead%2Ctypedesc"><span class="Identifier">genericHead</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  244. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  245. <dd>
  246. <p>Accepts an instantiated generic type and returns its uninstantiated form. A compile-time error will be produced if the supplied type is not generic.</p>
  247. <p><strong>See also:</strong></p>
  248. <ul class="simple"><li><a class="reference external" href="#stripGenericParams,typedesc">stripGenericParams proc</a></li>
  249. </ul>
  250. <p><strong class="examples_text">Example:</strong></p>
  251. <pre class="listing"><span class="Keyword">type</span>
  252. <span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">T</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Keyword">object</span>
  253. <span class="Identifier">FooInst</span> <span class="Operator">=</span> <span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span>
  254. <span class="Identifier">Foo2</span> <span class="Operator">=</span> <span class="Identifier">genericHead</span><span class="Punctuation">(</span><span class="Identifier">FooInst</span><span class="Punctuation">)</span>
  255. <span class="Identifier">doAssert</span> <span class="Identifier">Foo2</span> <span class="Keyword">is</span> <span class="Identifier">Foo</span> <span class="Keyword">and</span> <span class="Identifier">Foo</span> <span class="Keyword">is</span> <span class="Identifier">Foo2</span>
  256. <span class="Identifier">doAssert</span> <span class="Identifier">genericHead</span><span class="Punctuation">(</span><span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">Foo</span>
  257. <span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">compiles</span><span class="Punctuation">(</span><span class="Identifier">genericHead</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  258. <span class="Keyword">type</span> <span class="Identifier">Generic</span> <span class="Operator">=</span> <span class="Keyword">concept</span> <span class="Identifier">f</span>
  259. <span class="Keyword">type</span> <span class="Identifier">_</span> <span class="Operator">=</span> <span class="Identifier">genericHead</span><span class="Punctuation">(</span><span class="Identifier">typeof</span><span class="Punctuation">(</span><span class="Identifier">f</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  260. <span class="Keyword">proc</span> <span class="Identifier">bar</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">Generic</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">typeof</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span> <span class="Operator">=</span> <span class="Identifier">a</span>
  261. <span class="Identifier">doAssert</span> <span class="Identifier">bar</span><span class="Punctuation">(</span><span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">default</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="Punctuation">)</span>
  262. <span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">compiles</span> <span class="Identifier">bar</span><span class="Punctuation">(</span><span class="Identifier">string</span><span class="Operator">.</span><span class="Identifier">default</span><span class="Punctuation">)</span>
  263. <span class="Keyword">when</span> <span class="Identifier">false</span><span class="Punctuation">:</span> <span class="Comment"># these don't work yet</span>
  264. <span class="Identifier">doAssert</span> <span class="Identifier">genericHead</span><span class="Punctuation">(</span><span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">]</span> <span class="Keyword">is</span> <span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">]</span>
  265. <span class="Identifier">doAssert</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Identifier">genericHead</span> <span class="Keyword">is</span> <span class="Identifier">seq</span></pre>
  266. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L54" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  267. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L54" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  268. </dd>
  269. </div>
  270. </div>
  271. <div id="hasClosure-procs-all">
  272. <div id="hasClosure,NimNode">
  273. <dt><pre><span class="Keyword">proc</span> <a href="#hasClosure%2CNimNode"><span class="Identifier">hasClosure</span></a><span class="Other">(</span><span class="Identifier">fn</span><span class="Other">:</span> <a href="system.html#NimNode"><span class="Identifier">NimNode</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  274. <dd>
  275. Returns true if the func/proc/etc <tt class="docutils literal"><span class="pre"><span class="Identifier">fn</span></span></tt> has <tt class="docutils literal"><span class="pre"><span class="Identifier">closure</span></span></tt>. <tt class="docutils literal"><span class="pre"><span class="Identifier">fn</span></span></tt> has to be a resolved symbol of kind <tt class="docutils literal"><span class="pre"><span class="Identifier">nnkSym</span></span></tt>. This implies that the macro that calls this proc should accept <tt class="docutils literal"><span class="pre"><span class="Identifier">typed</span></span></tt> arguments and not <tt class="docutils literal"><span class="pre"><span class="Identifier">untyped</span></span></tt> arguments.
  276. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L341" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  277. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L341" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  278. </dd>
  279. </div>
  280. </div>
  281. <div id="hasDefaultValue-procs-all">
  282. <div id="hasDefaultValue,typedesc">
  283. <dt><pre><span class="Keyword">proc</span> <a href="#hasDefaultValue%2Ctypedesc"><span class="Identifier">hasDefaultValue</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  284. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  285. <dd>
  286. Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> has a valid default value.
  287. <p><strong class="examples_text">Example:</strong></p>
  288. <pre class="listing"><span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">experimental</span><span class="Punctuation">:</span> <span class="StringLit">&quot;strictNotNil&quot;</span><span class="Operator">.</span><span class="Punctuation">}</span>
  289. <span class="Keyword">type</span>
  290. <span class="Identifier">NilableObject</span> <span class="Operator">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
  291. <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
  292. <span class="Keyword">Object</span> <span class="Operator">=</span> <span class="Identifier">NilableObject</span> <span class="Keyword">not</span> <span class="Keyword">nil</span>
  293. <span class="Identifier">RequiresInit</span><span class="Punctuation">[</span><span class="Identifier">T</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Keyword">object</span>
  294. <span class="Identifier">a</span> <span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">requiresInit</span><span class="Operator">.</span><span class="Punctuation">}</span><span class="Punctuation">:</span> <span class="Identifier">T</span>
  295. <span class="Identifier">assert</span> <span class="Identifier">hasDefaultValue</span><span class="Punctuation">(</span><span class="Identifier">NilableObject</span><span class="Punctuation">)</span>
  296. <span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="Identifier">hasDefaultValue</span><span class="Punctuation">(</span><span class="Keyword">Object</span><span class="Punctuation">)</span>
  297. <span class="Identifier">assert</span> <span class="Identifier">hasDefaultValue</span><span class="Punctuation">(</span><span class="Identifier">string</span><span class="Punctuation">)</span>
  298. <span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="Identifier">hasDefaultValue</span><span class="Punctuation">(</span><span class="Keyword">var</span> <span class="Identifier">string</span><span class="Punctuation">)</span>
  299. <span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="Identifier">hasDefaultValue</span><span class="Punctuation">(</span><span class="Identifier">RequiresInit</span><span class="Punctuation">[</span><span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
  300. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L99" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  301. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L99" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  302. </dd>
  303. </div>
  304. </div>
  305. <div id="isNamedTuple-procs-all">
  306. <div id="isNamedTuple,typedesc">
  307. <dt><pre><span class="Keyword">proc</span> <a href="#isNamedTuple%2Ctypedesc"><span class="Identifier">isNamedTuple</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  308. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  309. <dd>
  310. Returns true for named tuples, false for any other type.
  311. <p><strong class="examples_text">Example:</strong></p>
  312. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">isNamedTuple</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">)</span>
  313. <span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">isNamedTuple</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="Identifier">string</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">)</span><span class="Punctuation">)</span>
  314. <span class="Identifier">doAssert</span> <span class="Identifier">isNamedTuple</span><span class="Punctuation">(</span><span class="Keyword">tuple</span><span class="Punctuation">[</span><span class="Identifier">name</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">,</span> <span class="Identifier">age</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span></pre>
  315. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L116" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  316. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L116" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  317. </dd>
  318. </div>
  319. </div>
  320. <div id="name-procs-all">
  321. <div id="name,typedesc">
  322. <dt><pre><span class="Keyword">proc</span> <a href="#name%2Ctypedesc"><span class="Identifier">name</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#string"><span class="Identifier">string</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  323. <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  324. <dd>
  325. <p>Returns the name of <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
  326. <p>Alias for <a class="reference external" href="dollars.html#$,typedesc">system.`$`(t)</a> since Nim v0.20.</p>
  327. <p><strong class="examples_text">Example:</strong></p>
  328. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">name</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;int&quot;</span>
  329. <span class="Identifier">doAssert</span> <span class="Identifier">name</span><span class="Punctuation">(</span><span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;seq[string]&quot;</span></pre>
  330. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L37" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  331. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L37" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  332. </dd>
  333. </div>
  334. </div>
  335. <div id="rangeBase-procs-all">
  336. <div id="rangeBase,typedesc[range]">
  337. <dt><pre><span class="Keyword">proc</span> <a href="#rangeBase%2Ctypedesc%5Brange%5D"><span class="Identifier">rangeBase</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">[</span><a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  338. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  339. <dd>
  340. <p>Returns the base type for range types, or the type itself otherwise.</p>
  341. <p><strong>See also:</strong></p>
  342. <ul class="simple"><li><a class="reference external" href="#rangeBase.t,T">rangeBase template</a></li>
  343. </ul>
  344. <p><strong class="examples_text">Example:</strong></p>
  345. <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">MyRange</span> <span class="Operator">=</span> <span class="Identifier">range</span><span class="Punctuation">[</span><span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">5</span><span class="Punctuation">]</span>
  346. <span class="Keyword">type</span> <span class="Identifier">MyEnum</span> <span class="Operator">=</span> <span class="Keyword">enum</span> <span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">,</span> <span class="Identifier">c</span>
  347. <span class="Keyword">type</span> <span class="Identifier">MyEnumRange</span> <span class="Operator">=</span> <span class="Identifier">range</span><span class="Punctuation">[</span><span class="Identifier">b</span><span class="Operator">..</span><span class="Identifier">c</span><span class="Punctuation">]</span>
  348. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">MyRange</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span>
  349. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">MyEnumRange</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">MyEnum</span>
  350. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">range</span><span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">a</span><span class="CharLit">'..'</span><span class="Identifier">z</span><span class="CharLit">']) is char</span></pre>
  351. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L133" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  352. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L133" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  353. </dd>
  354. </div>
  355. </div>
  356. <div id="stripGenericParams-procs-all">
  357. <div id="stripGenericParams,typedesc">
  358. <dt><pre><span class="Keyword">proc</span> <a href="#stripGenericParams%2Ctypedesc"><span class="Identifier">stripGenericParams</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  359. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  360. <dd>
  361. This trait is similar to <a class="reference external" href="#genericHead,typedesc">genericHead</a>, but instead of producing an error for non-generic types, it will just return them unmodified.
  362. <p><strong class="examples_text">Example:</strong></p>
  363. <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">T</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Keyword">object</span>
  364. <span class="Identifier">doAssert</span> <span class="Identifier">stripGenericParams</span><span class="Punctuation">(</span><span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">Foo</span>
  365. <span class="Identifier">doAssert</span> <span class="Identifier">stripGenericParams</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span></pre>
  366. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L84" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  367. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L84" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  368. </dd>
  369. </div>
  370. </div>
  371. <div id="supportsCopyMem-procs-all">
  372. <div id="supportsCopyMem,typedesc">
  373. <dt><pre><span class="Keyword">proc</span> <a href="#supportsCopyMem%2Ctypedesc"><span class="Identifier">supportsCopyMem</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  374. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  375. <dd>
  376. <p>Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> is safe to use for <span id="copymem_1">copyMem</span>.</p>
  377. <p>Other languages name a type like these <span id="blob_1">blob</span>.</p>
  378. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L94" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  379. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L94" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  380. </dd>
  381. </div>
  382. </div>
  383. <div id="tupleLen-procs-all">
  384. <div id="tupleLen,typedesc[]">
  385. <dt><pre><span class="Keyword">proc</span> <a href="#tupleLen%2Ctypedesc%5B%5D"><span class="Identifier">tupleLen</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">&quot;TypeTrait&quot;</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
  386. <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
  387. <dd>
  388. <p>Returns the number of elements of the tuple type <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.</p>
  389. <p><strong>See also:</strong></p>
  390. <ul class="simple"><li><a class="reference external" href="#tupleLen.t">tupleLen template</a></li>
  391. </ul>
  392. <p><strong class="examples_text">Example:</strong></p>
  393. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">tupleLen</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">float</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
  394. <span class="Identifier">doAssert</span> <span class="Identifier">tupleLen</span><span class="Punctuation">(</span><span class="Keyword">tuple</span><span class="Punctuation">[</span><span class="Identifier">name</span><span class="Punctuation">:</span> <span class="Identifier">string</span><span class="Punctuation">,</span> <span class="Identifier">age</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span></pre>
  395. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L196" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  396. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L196" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  397. </dd>
  398. </div>
  399. </div>
  400. </dl>
  401. </div>
  402. <div class="section" id="17">
  403. <h1><a class="toc-backref" href="#17">Macros</a></h1>
  404. <dl class="item">
  405. <div id="enumLen-macros-all">
  406. <div id="enumLen.m,typedesc[]">
  407. <dt><pre><span class="Keyword">macro</span> <a href="#enumLen.m%2Ctypedesc%5B%5D"><span class="Identifier">enumLen</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">[</span><span class="Keyword">enum</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a></pre></dt>
  408. <dd>
  409. Returns the number of items in the enum <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
  410. <p><strong class="examples_text">Example:</strong></p>
  411. <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">Foo</span> <span class="Operator">=</span> <span class="Keyword">enum</span>
  412. <span class="Identifier">fooItem1</span>
  413. <span class="Identifier">fooItem2</span>
  414. <span class="Identifier">doAssert</span> <span class="Identifier">Foo</span><span class="Operator">.</span><span class="Identifier">enumLen</span> <span class="Operator">==</span> <span class="DecNumber">2</span></pre>
  415. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L243" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  416. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L243" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  417. </dd>
  418. </div>
  419. </div>
  420. </dl>
  421. </div>
  422. <div class="section" id="18">
  423. <h1><a class="toc-backref" href="#18">Templates</a></h1>
  424. <dl class="item">
  425. <div id="distinctBase-templates-all">
  426. <div id="distinctBase.t,T,staticbool">
  427. <dt><pre><span class="Keyword">template</span> <a href="#distinctBase.t%2CT%2Cstaticbool"><span class="Identifier">distinctBase</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">recursive</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">bool</span> <span class="Other">=</span> <span class="Identifier">true</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
  428. <dd>
  429. Overload of <a class="reference external" href="#distinctBase,typedesc,static[bool]">distinctBase</a> for values.
  430. <p><strong class="examples_text">Example:</strong></p>
  431. <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">MyInt</span> <span class="Operator">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int</span>
  432. <span class="Keyword">type</span> <span class="Identifier">MyOtherInt</span> <span class="Operator">=</span> <span class="Keyword">distinct</span> <span class="Identifier">MyInt</span>
  433. <span class="Identifier">doAssert</span> <span class="FloatNumber">12.</span><span class="Identifier">MyInt</span><span class="Operator">.</span><span class="Identifier">distinctBase</span> <span class="Operator">==</span> <span class="DecNumber">12</span>
  434. <span class="Identifier">doAssert</span> <span class="FloatNumber">12.</span><span class="Identifier">MyOtherInt</span><span class="Operator">.</span><span class="Identifier">distinctBase</span> <span class="Operator">==</span> <span class="DecNumber">12</span>
  435. <span class="Identifier">doAssert</span> <span class="FloatNumber">12.</span><span class="Identifier">MyOtherInt</span><span class="Operator">.</span><span class="Identifier">distinctBase</span><span class="Punctuation">(</span><span class="Identifier">false</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">MyInt</span>
  436. <span class="Identifier">doAssert</span> <span class="FloatNumber">12.</span><span class="Identifier">distinctBase</span> <span class="Operator">==</span> <span class="DecNumber">12</span></pre>
  437. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L182" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  438. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L182" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  439. </dd>
  440. </div>
  441. </div>
  442. <div id="elementType-templates-all">
  443. <div id="elementType.t,untyped">
  444. <dt><pre><span class="Keyword">template</span> <a href="#elementType.t%2Cuntyped"><span class="Identifier">elementType</span></a><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a></pre></dt>
  445. <dd>
  446. Returns the element type of <tt class="docutils literal"><span class="pre"><span class="Identifier">a</span></span></tt>, which can be any iterable (over which you can iterate).
  447. <p><strong class="examples_text">Example:</strong></p>
  448. <pre class="listing"><span class="Keyword">iterator</span> <span class="Identifier">myiter</span><span class="Punctuation">(</span><span class="Identifier">n</span><span class="Punctuation">:</span> <span class="Identifier">int</span><span class="Punctuation">)</span><span class="Punctuation">:</span> <span class="Identifier">auto</span> <span class="Operator">=</span>
  449. <span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="DecNumber">0</span> <span class="Operator">..&lt;</span> <span class="Identifier">n</span><span class="Punctuation">:</span>
  450. <span class="Keyword">yield</span> <span class="Identifier">i</span>
  451. <span class="Identifier">doAssert</span> <span class="Identifier">elementType</span><span class="Punctuation">(</span><span class="Operator">@</span><span class="Punctuation">[</span><span class="DecNumber">1</span><span class="Punctuation">,</span><span class="DecNumber">2</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span>
  452. <span class="Identifier">doAssert</span> <span class="Identifier">elementType</span><span class="Punctuation">(</span><span class="StringLit">&quot;asdf&quot;</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">char</span>
  453. <span class="Identifier">doAssert</span> <span class="Identifier">elementType</span><span class="Punctuation">(</span><span class="Identifier">myiter</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span></pre>
  454. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L227" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  455. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L227" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  456. </dd>
  457. </div>
  458. </div>
  459. <div id="genericParams-templates-all">
  460. <div id="genericParams.t,typedesc">
  461. <dt><pre><span class="Keyword">template</span> <a href="#genericParams.t%2Ctypedesc"><span class="Identifier">genericParams</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
  462. <dd>
  463. <p>Returns the tuple of generic parameters for the generic type <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.</p>
  464. <p><strong>Note:</strong> For the builtin array type, the index generic parameter will <strong>always</strong> become a range type after it's bound to a variable.</p>
  465. <p><strong class="examples_text">Example:</strong></p>
  466. <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">T1</span><span class="Punctuation">,</span> <span class="Identifier">T2</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Keyword">object</span>
  467. <span class="Identifier">doAssert</span> <span class="Identifier">genericParams</span><span class="Punctuation">(</span><span class="Identifier">Foo</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Punctuation">(</span><span class="Identifier">float</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">)</span>
  468. <span class="Keyword">type</span> <span class="Identifier">Bar</span><span class="Punctuation">[</span><span class="Identifier">N</span><span class="Punctuation">:</span> <span class="Keyword">static</span> <span class="Identifier">float</span><span class="Punctuation">,</span> <span class="Identifier">T</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Keyword">object</span>
  469. <span class="Identifier">doAssert</span> <span class="Identifier">genericParams</span><span class="Punctuation">(</span><span class="Identifier">Bar</span><span class="Punctuation">[</span><span class="FloatNumber">1.0</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Punctuation">(</span><span class="Identifier">StaticParam</span><span class="Punctuation">[</span><span class="FloatNumber">1.0</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">)</span>
  470. <span class="Identifier">doAssert</span> <span class="Identifier">genericParams</span><span class="Punctuation">(</span><span class="Identifier">Bar</span><span class="Punctuation">[</span><span class="FloatNumber">1.0</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">value</span> <span class="Operator">==</span> <span class="FloatNumber">1.0</span>
  471. <span class="Identifier">doAssert</span> <span class="Identifier">genericParams</span><span class="Punctuation">(</span><span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">Bar</span><span class="Punctuation">[</span><span class="FloatNumber">2.0</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">get</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">Bar</span><span class="Punctuation">[</span><span class="FloatNumber">2.0</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span>
  472. <span class="Keyword">var</span> <span class="Identifier">s</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">Bar</span><span class="Punctuation">[</span><span class="FloatNumber">3.0</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">]</span>
  473. <span class="Identifier">doAssert</span> <span class="Identifier">genericParams</span><span class="Punctuation">(</span><span class="Identifier">typeof</span><span class="Punctuation">(</span><span class="Identifier">s</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Punctuation">(</span><span class="Identifier">Bar</span><span class="Punctuation">[</span><span class="FloatNumber">3.0</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">]</span><span class="Punctuation">,</span><span class="Punctuation">)</span>
  474. <span class="Identifier">doAssert</span> <span class="Identifier">genericParams</span><span class="Punctuation">(</span><span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Punctuation">(</span><span class="Identifier">StaticParam</span><span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">)</span>
  475. <span class="Keyword">var</span> <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">array</span><span class="Punctuation">[</span><span class="DecNumber">10</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">]</span>
  476. <span class="Identifier">doAssert</span> <span class="Identifier">genericParams</span><span class="Punctuation">(</span><span class="Identifier">typeof</span><span class="Punctuation">(</span><span class="Identifier">a</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Punctuation">(</span><span class="Identifier">range</span><span class="Punctuation">[</span><span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">9</span><span class="Punctuation">]</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">)</span></pre>
  477. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L313" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  478. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L313" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  479. </dd>
  480. </div>
  481. </div>
  482. <div id="get-templates-all">
  483. <div id="get.t,typedesc[],staticint">
  484. <dt><pre><span class="Keyword">template</span> <a href="#get.t%2Ctypedesc%5B%5D%2Cstaticint"><span class="Identifier">get</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">[</span><span class="Keyword">tuple</span><span class="Other">]</span><span class="Other">;</span> <span class="Identifier">i</span><span class="Other">:</span> <a href="system.html#static"><span class="Identifier">static</span></a> <span class="Identifier">int</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
  485. <dd>
  486. Returns the <tt class="docutils literal"><span class="pre"><span class="Identifier">i</span></span></tt>-th element of <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
  487. <p><strong class="examples_text">Example:</strong></p>
  488. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">get</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">int</span><span class="Punctuation">,</span> <span class="Identifier">float</span><span class="Punctuation">,</span> <span class="Identifier">string</span><span class="Punctuation">)</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">float</span></pre>
  489. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L215" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  490. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L215" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  491. </dd>
  492. </div>
  493. </div>
  494. <div id="pointerBase-templates-all">
  495. <div id="pointerBase.t,typedesc[]">
  496. <dt><pre><span class="Keyword">template</span> <a href="#pointerBase.t%2Ctypedesc%5B%5D"><span class="Identifier">pointerBase</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Operator">_</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">[</span><span class="Keyword">ptr</span> <span class="Identifier">T</span> <span class="Operator">|</span> <span class="Keyword">ref</span> <span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a></pre></dt>
  497. <dd>
  498. Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt> for <tt class="docutils literal"><span class="pre"><span class="Keyword">ref</span> <span class="Identifier">T</span> <span class="Operator">|</span> <span class="Keyword">ptr</span> <span class="Identifier">T</span></span></tt>.
  499. <p><strong class="examples_text">Example:</strong></p>
  500. <pre class="listing"><span class="Identifier">assert</span> <span class="Punctuation">(</span><span class="Keyword">ref</span> <span class="Identifier">int</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">pointerBase</span> <span class="Keyword">is</span> <span class="Identifier">int</span>
  501. <span class="Keyword">type</span> <span class="Identifier">A</span> <span class="Operator">=</span> <span class="Keyword">ptr</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">]</span>
  502. <span class="Identifier">assert</span> <span class="Identifier">A</span><span class="Operator">.</span><span class="Identifier">pointerBase</span> <span class="Keyword">is</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">float</span><span class="Punctuation">]</span>
  503. <span class="Identifier">assert</span> <span class="Punctuation">(</span><span class="Keyword">ref</span> <span class="Identifier">A</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">pointerBase</span> <span class="Keyword">is</span> <span class="Identifier">A</span> <span class="Comment"># not seq[float]</span>
  504. <span class="Identifier">assert</span> <span class="Punctuation">(</span><span class="Keyword">var</span> <span class="Identifier">s</span> <span class="Operator">=</span> <span class="StringLit">&quot;abc&quot;</span><span class="Punctuation">;</span> <span class="Identifier">s</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Operator">.</span><span class="Keyword">addr</span><span class="Punctuation">)</span><span class="Operator">.</span><span class="Identifier">typeof</span><span class="Operator">.</span><span class="Identifier">pointerBase</span> <span class="Keyword">is</span> <span class="Identifier">char</span></pre>
  505. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L123" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  506. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L123" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  507. </dd>
  508. </div>
  509. </div>
  510. <div id="rangeBase-templates-all">
  511. <div id="rangeBase.t,T">
  512. <dt><pre><span class="Keyword">template</span> <a href="#rangeBase.t%2CT"><span class="Identifier">rangeBase</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
  513. <dd>
  514. Overload of <a class="reference external" href="#rangeBase,typedesc,static[bool]">rangeBase</a> for values.
  515. <p><strong class="examples_text">Example:</strong></p>
  516. <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">MyRange</span> <span class="Operator">=</span> <span class="Identifier">range</span><span class="Punctuation">[</span><span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">5</span><span class="Punctuation">]</span>
  517. <span class="Keyword">type</span> <span class="Identifier">MyEnum</span> <span class="Operator">=</span> <span class="Keyword">enum</span> <span class="Identifier">a</span><span class="Punctuation">,</span> <span class="Identifier">b</span><span class="Punctuation">,</span> <span class="Identifier">c</span>
  518. <span class="Keyword">type</span> <span class="Identifier">MyEnumRange</span> <span class="Operator">=</span> <span class="Identifier">range</span><span class="Punctuation">[</span><span class="Identifier">b</span><span class="Operator">..</span><span class="Identifier">c</span><span class="Punctuation">]</span>
  519. <span class="Keyword">let</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="Identifier">MyRange</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">)</span>
  520. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">int</span>
  521. <span class="Identifier">doAssert</span> <span class="Operator">$</span><span class="Identifier">typeof</span><span class="Punctuation">(</span><span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;int&quot;</span>
  522. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">x</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
  523. <span class="Keyword">let</span> <span class="Identifier">y</span><span class="Punctuation">:</span> <span class="Identifier">set</span><span class="Punctuation">[</span><span class="Identifier">MyEnumRange</span><span class="Punctuation">]</span> <span class="Operator">=</span> <span class="Punctuation">{</span><span class="Identifier">c</span><span class="Punctuation">}</span>
  524. <span class="Keyword">for</span> <span class="Identifier">e</span> <span class="Keyword">in</span> <span class="Identifier">y</span><span class="Punctuation">:</span>
  525. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">e</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">MyEnum</span>
  526. <span class="Identifier">doAssert</span> <span class="Operator">$</span><span class="Identifier">typeof</span><span class="Punctuation">(</span><span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">e</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;MyEnum&quot;</span>
  527. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">e</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="Identifier">c</span>
  528. <span class="Keyword">let</span> <span class="Identifier">z</span><span class="Punctuation">:</span> <span class="Identifier">seq</span><span class="Punctuation">[</span><span class="Identifier">range</span><span class="Punctuation">[</span><span class="Punctuation">'</span><span class="Identifier">a</span><span class="CharLit">'..'</span><span class="Identifier">z</span><span class="CharLit">']] = @['</span><span class="Identifier">c</span><span class="CharLit">']</span>
  529. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">z</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">char</span>
  530. <span class="Identifier">doAssert</span> <span class="Operator">$</span><span class="Identifier">typeof</span><span class="Punctuation">(</span><span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">z</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="StringLit">&quot;char&quot;</span>
  531. <span class="Identifier">doAssert</span> <span class="Identifier">rangeBase</span><span class="Punctuation">(</span><span class="Identifier">z</span><span class="Punctuation">[</span><span class="DecNumber">0</span><span class="Punctuation">]</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="CharLit">'c'</span></pre>
  532. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L146" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  533. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L146" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  534. </dd>
  535. </div>
  536. </div>
  537. <div id="toSigned-templates-all">
  538. <div id="toSigned.t,typedesc[]">
  539. <dt><pre><span class="Keyword">template</span> <a href="#toSigned.t%2Ctypedesc%5B%5D"><span class="Identifier">toSigned</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">[</span><a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a> <span class="Keyword">and</span> <span class="Keyword">not</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
  540. <dd>
  541. Returns a signed type with same bit size as <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
  542. <p><strong class="examples_text">Example:</strong></p>
  543. <pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">int8</span><span class="Operator">.</span><span class="Identifier">toSigned</span> <span class="Keyword">is</span> <span class="Identifier">int8</span>
  544. <span class="Identifier">assert</span> <span class="Identifier">uint16</span><span class="Operator">.</span><span class="Identifier">toSigned</span> <span class="Keyword">is</span> <span class="Identifier">int16</span>
  545. <span class="Comment"># range types are currently unsupported:</span>
  546. <span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="Identifier">compiles</span><span class="Punctuation">(</span><span class="Identifier">toSigned</span><span class="Punctuation">(</span><span class="Identifier">range</span><span class="Punctuation">[</span><span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
  547. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L364" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  548. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L364" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  549. </dd>
  550. </div>
  551. </div>
  552. <div id="toUnsigned-templates-all">
  553. <div id="toUnsigned.t,typedesc[]">
  554. <dt><pre><span class="Keyword">template</span> <a href="#toUnsigned.t%2Ctypedesc%5B%5D"><span class="Identifier">toUnsigned</span></a><span class="Other">(</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#typedesc"><span class="Identifier">typedesc</span></a><span class="Other">[</span><a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a> <span class="Keyword">and</span> <span class="Keyword">not</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
  555. <dd>
  556. Returns an unsigned type with same bit size as <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
  557. <p><strong class="examples_text">Example:</strong></p>
  558. <pre class="listing"><span class="Identifier">assert</span> <span class="Identifier">int8</span><span class="Operator">.</span><span class="Identifier">toUnsigned</span> <span class="Keyword">is</span> <span class="Identifier">uint8</span>
  559. <span class="Identifier">assert</span> <span class="Identifier">uint</span><span class="Operator">.</span><span class="Identifier">toUnsigned</span> <span class="Keyword">is</span> <span class="Identifier">uint</span>
  560. <span class="Identifier">assert</span> <span class="Identifier">int</span><span class="Operator">.</span><span class="Identifier">toUnsigned</span> <span class="Keyword">is</span> <span class="Identifier">uint</span>
  561. <span class="Comment"># range types are currently unsupported:</span>
  562. <span class="Identifier">assert</span> <span class="Keyword">not</span> <span class="Identifier">compiles</span><span class="Punctuation">(</span><span class="Identifier">toUnsigned</span><span class="Punctuation">(</span><span class="Identifier">range</span><span class="Punctuation">[</span><span class="FloatNumber">0.</span><span class="Operator">.</span><span class="DecNumber">7</span><span class="Punctuation">]</span><span class="Punctuation">)</span><span class="Punctuation">)</span></pre>
  563. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L349" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  564. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L349" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  565. </dd>
  566. </div>
  567. </div>
  568. <div id="tupleLen-templates-all">
  569. <div id="tupleLen.t">
  570. <dt><pre><span class="Keyword">template</span> <a href="#tupleLen.t"><span class="Identifier">tupleLen</span></a><span class="Other">(</span><span class="Identifier">t</span><span class="Other">:</span> <span class="Keyword">tuple</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a></pre></dt>
  571. <dd>
  572. <p>Returns the number of elements of the tuple <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
  573. <p><strong>See also:</strong></p>
  574. <ul class="simple"><li><a class="reference external" href="#tupleLen,typedesc">tupleLen proc</a></li>
  575. </ul>
  576. <p><strong class="examples_text">Example:</strong></p>
  577. <pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">tupleLen</span><span class="Punctuation">(</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">2</span><span class="Punctuation">)</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span></pre>
  578. <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L205" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
  579. <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L205" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
  580. </dd>
  581. </div>
  582. </div>
  583. </dl>
  584. </div>
  585. </div>
  586. </div>
  587. <div class="twelve-columns footer">
  588. <span class="nim-sprite"></span>
  589. <br>
  590. <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-03 14:57:04 UTC</small>
  591. </div>
  592. </div>
  593. </div>
  594. <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
  595. </body>
  596. </html>