123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- <?xml version="1.0" encoding="utf-8" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <!-- This file is generated by Nim. -->
- <html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>std/typetraits</title>
- <!-- Google fonts -->
- <link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
- <link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
- <!-- Favicon -->
- <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=="/>
- <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=">
- <!-- CSS -->
- <link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
- <!-- JS -->
- <script type="text/javascript" src="dochack.js?v=2.3.1"></script>
- </head>
- <body>
- <div class="document" id="documentId">
- <div class="container">
- <h1 class="title">std/typetraits</h1>
- <div class="row">
- <div class="three columns">
- <div class="theme-select-wrapper">
- <label for="theme-select">Theme: </label>
- <select id="theme-select" onchange="setTheme(this.value)">
- <option value="auto">🌗 Match OS</option>
- <option value="dark">🌑 Dark</option>
- <option value="light">🌕 Light</option>
- </select>
- </div>
- <div id="global-links">
- <ul class="simple-boot">
- <li><a href="manual.html">Manual</a></li>
- <li><a href="lib.html">Standard library</a></li>
- <li> <a id="indexLink" href="theindex.html">Index</a></li>
- <li><a href="compiler/theindex.html">Compiler docs</a></li>
- <li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
- <li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
- </ul>
- </div>
- <div id="searchInputDiv">
- Search: <input type="search" id="searchInput"
- oninput="search()" />
- </div>
-
- <ul class="simple simple-toc" id="toc-list">
- <li>
- <a class="reference reference-toplevel" href="#6" id="56">Imports</a>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
- <ul class="simple simple-toc-section">
- <li><a class="reference" href="#HoleyEnum" title="HoleyEnum = (not Ordinal) and enum">HoleyEnum</a></li>
- <li><a class="reference" href="#OrdinalEnum" title="OrdinalEnum = Ordinal and enum">OrdinalEnum</a></li>
- <li><a class="reference" href="#StaticParam" title="StaticParam[value] = object">StaticParam</a></li>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">arity
- <li><a class="reference" href="#arity%2Ctypedesc" title="arity(t: typedesc): int">arity(t: typedesc): int</a></li>
- </ul>
- <ul class="simple nested-toc-section">distinctBase
- <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>
- </ul>
- <ul class="simple nested-toc-section">genericHead
- <li><a class="reference" href="#genericHead%2Ctypedesc" title="genericHead(t: typedesc): typedesc">genericHead(t: typedesc): typedesc</a></li>
- </ul>
- <ul class="simple nested-toc-section">hasClosure
- <li><a class="reference" href="#hasClosure%2CNimNode" title="hasClosure(fn: NimNode): bool">hasClosure(fn: NimNode): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">hasDefaultValue
- <li><a class="reference" href="#hasDefaultValue%2Ctypedesc" title="hasDefaultValue(t: typedesc): bool">hasDefaultValue(t: typedesc): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">isNamedTuple
- <li><a class="reference" href="#isNamedTuple%2Ctypedesc" title="isNamedTuple(T: typedesc): bool">isNamedTuple(T: typedesc): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">name
- <li><a class="reference" href="#name%2Ctypedesc" title="name(t: typedesc): string">name(t: typedesc): string</a></li>
- </ul>
- <ul class="simple nested-toc-section">rangeBase
- <li><a class="reference" href="#rangeBase%2Ctypedesc%5Brange%5D" title="rangeBase(T: typedesc[range]): typedesc">rangeBase(T: typedesc[range]): typedesc</a></li>
- </ul>
- <ul class="simple nested-toc-section">stripGenericParams
- <li><a class="reference" href="#stripGenericParams%2Ctypedesc" title="stripGenericParams(t: typedesc): typedesc">stripGenericParams(t: typedesc): typedesc</a></li>
- </ul>
- <ul class="simple nested-toc-section">supportsCopyMem
- <li><a class="reference" href="#supportsCopyMem%2Ctypedesc" title="supportsCopyMem(t: typedesc): bool">supportsCopyMem(t: typedesc): bool</a></li>
- </ul>
- <ul class="simple nested-toc-section">tupleLen
- <li><a class="reference" href="#tupleLen%2Ctypedesc%5B%5D" title="tupleLen(T: typedesc[tuple]): int">tupleLen(T: typedesc[tuple]): int</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#17" id="67">Macros</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">enumLen
- <li><a class="reference" href="#enumLen.m%2Ctypedesc%5B%5D" title="enumLen(T: typedesc[enum]): int">enumLen(T: typedesc[enum]): int</a></li>
- </ul>
- </ul>
- </details>
- </li>
- <li>
- <details open>
- <summary><a class="reference reference-toplevel" href="#18" id="68">Templates</a></summary>
- <ul class="simple simple-toc-section">
- <ul class="simple nested-toc-section">distinctBase
- <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>
- </ul>
- <ul class="simple nested-toc-section">elementType
- <li><a class="reference" href="#elementType.t%2Cuntyped" title="elementType(a: untyped): typedesc">elementType(a: untyped): typedesc</a></li>
- </ul>
- <ul class="simple nested-toc-section">genericParams
- <li><a class="reference" href="#genericParams.t%2Ctypedesc" title="genericParams(T: typedesc): untyped">genericParams(T: typedesc): untyped</a></li>
- </ul>
- <ul class="simple nested-toc-section">get
- <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>
- </ul>
- <ul class="simple nested-toc-section">pointerBase
- <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>
- </ul>
- <ul class="simple nested-toc-section">rangeBase
- <li><a class="reference" href="#rangeBase.t%2CT" title="rangeBase[T: range](a: T): untyped">rangeBase[T: range](a: T): untyped</a></li>
- </ul>
- <ul class="simple nested-toc-section">toSigned
- <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>
- </ul>
- <ul class="simple nested-toc-section">toUnsigned
- <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>
- </ul>
- <ul class="simple nested-toc-section">tupleLen
- <li><a class="reference" href="#tupleLen.t" title="tupleLen(t: tuple): int">tupleLen(t: tuple): int</a></li>
- </ul>
- </ul>
- </details>
- </li>
- </ul>
- </div>
- <div class="nine columns" id="content">
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L1" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
- <div id="tocRoot"></div>
-
- <p class="module-desc"><p>This module defines compile-time reflection procs for working with types.</p>
- <p>Unstable API.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">import</span> <span class="Identifier">std</span><span class="Operator">/</span><span class="Identifier">typetraits</span>
- <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>
- <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>
- <span class="Identifier">assert</span> <span class="Identifier">A</span> <span class="Keyword">is</span> <span class="Keyword">enum</span>
- <span class="Identifier">assert</span> <span class="Identifier">A</span> <span class="Keyword">is</span> <span class="Identifier">HoleyEnum</span>
- <span class="Identifier">assert</span> <span class="Identifier">A</span> <span class="Keyword">isnot</span> <span class="Identifier">OrdinalEnum</span>
- <span class="Identifier">assert</span> <span class="Identifier">B</span> <span class="Keyword">isnot</span> <span class="Identifier">HoleyEnum</span>
- <span class="Identifier">assert</span> <span class="Identifier">B</span> <span class="Keyword">is</span> <span class="Identifier">OrdinalEnum</span>
- <span class="Identifier">assert</span> <span class="Identifier">int</span> <span class="Keyword">isnot</span> <span class="Identifier">HoleyEnum</span>
- <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>
- <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>
- <div class="section" id="6">
- <h1><a class="toc-backref" href="#6">Imports</a></h1>
- <dl class="item">
- <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>
- </dl>
- </div>
- <div class="section" id="7">
- <h1><a class="toc-backref" href="#7">Types</a></h1>
- <dl class="item">
- <div id="HoleyEnum">
- <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>
- <dd>
-
- Enum with holes.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L22" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L22" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="OrdinalEnum">
- <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>
- <dd>
-
- Enum without holes.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L23" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L23" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- <div id="StaticParam">
- <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>
- <dd>
-
- Used to wrap a static value in <a class="reference external" href="#genericParams.t,typedesc">genericParams</a>.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L223" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L223" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </dl>
- </div>
- <div class="section" id="12">
- <h1><a class="toc-backref" href="#12">Procs</a></h1>
- <dl class="item">
- <div id="arity-procs-all">
- <div id="arity,typedesc">
- <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">"TypeTrait"</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>
- <dd>
-
- Returns the arity of <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>. This is the number of "type" 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L45" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L45" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="distinctBase-procs-all">
- <div id="distinctBase,typedesc,staticbool">
- <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> {.
- <span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"TypeTrait"</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>
- <dd>
-
- <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>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#distinctBase.t,T,static[bool]">distinctBase template</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Keyword">type</span> <span class="Identifier">MyOtherInt</span> <span class="Operator">=</span> <span class="Keyword">distinct</span> <span class="Identifier">MyInt</span>
- <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>
- <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>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L167" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L167" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="genericHead-procs-all">
- <div id="genericHead,typedesc">
- <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">"TypeTrait"</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>
- <dd>
-
- <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>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#stripGenericParams,typedesc">stripGenericParams proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <span class="Keyword">type</span> <span class="Identifier">Generic</span> <span class="Operator">=</span> <span class="Keyword">concept</span> <span class="Identifier">f</span>
- <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>
- <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>
- <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>
- <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>
- <span class="Keyword">when</span> <span class="Identifier">false</span><span class="Punctuation">:</span> <span class="Comment"># these don't work yet</span>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L54" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L54" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="hasClosure-procs-all">
- <div id="hasClosure,NimNode">
- <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>
- <dd>
-
- 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.
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L341" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L341" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="hasDefaultValue-procs-all">
- <div id="hasDefaultValue,typedesc">
- <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">"TypeTrait"</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>
- <dd>
-
- Returns true if <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt> has a valid default value.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Punctuation">{</span><span class="Operator">.</span><span class="Identifier">experimental</span><span class="Punctuation">:</span> <span class="StringLit">"strictNotNil"</span><span class="Operator">.</span><span class="Punctuation">}</span>
- <span class="Keyword">type</span>
- <span class="Identifier">NilableObject</span> <span class="Operator">=</span> <span class="Keyword">ref</span> <span class="Keyword">object</span>
- <span class="Identifier">a</span><span class="Punctuation">:</span> <span class="Identifier">int</span>
- <span class="Keyword">Object</span> <span class="Operator">=</span> <span class="Identifier">NilableObject</span> <span class="Keyword">not</span> <span class="Keyword">nil</span>
- <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>
- <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>
- <span class="Identifier">assert</span> <span class="Identifier">hasDefaultValue</span><span class="Punctuation">(</span><span class="Identifier">NilableObject</span><span class="Punctuation">)</span>
- <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>
- <span class="Identifier">assert</span> <span class="Identifier">hasDefaultValue</span><span class="Punctuation">(</span><span class="Identifier">string</span><span class="Punctuation">)</span>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L99" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L99" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="isNamedTuple-procs-all">
- <div id="isNamedTuple,typedesc">
- <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">"TypeTrait"</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>
- <dd>
-
- Returns true for named tuples, false for any other type.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L116" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L116" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="name-procs-all">
- <div id="name,typedesc">
- <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">"TypeTrait"</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>
- <dd>
-
- <p>Returns the name of <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
- <p>Alias for <a class="reference external" href="dollars.html#$,typedesc">system.`$`(t)</a> since Nim v0.20.</p>
- <p><strong class="examples_text">Example:</strong></p>
- <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">"int"</span>
- <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">"seq[string]"</span></pre>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L37" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L37" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="rangeBase-procs-all">
- <div id="rangeBase,typedesc[range]">
- <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">"TypeTrait"</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>
- <dd>
-
- <p>Returns the base type for range types, or the type itself otherwise.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#rangeBase.t,T">rangeBase template</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L133" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L133" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="stripGenericParams-procs-all">
- <div id="stripGenericParams,typedesc">
- <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">"TypeTrait"</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>
- <dd>
-
- 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.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L84" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L84" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="supportsCopyMem-procs-all">
- <div id="supportsCopyMem,typedesc">
- <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">"TypeTrait"</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>
- <dd>
-
- <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>
- <p>Other languages name a type like these <span id="blob_1">blob</span>.</p>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L94" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L94" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="tupleLen-procs-all">
- <div id="tupleLen,typedesc[]">
- <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">"TypeTrait"</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>
- <dd>
-
- <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>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#tupleLen.t">tupleLen template</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L196" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L196" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="17">
- <h1><a class="toc-backref" href="#17">Macros</a></h1>
- <dl class="item">
- <div id="enumLen-macros-all">
- <div id="enumLen.m,typedesc[]">
- <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>
- <dd>
-
- Returns the number of items in the enum <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <pre class="listing"><span class="Keyword">type</span> <span class="Identifier">Foo</span> <span class="Operator">=</span> <span class="Keyword">enum</span>
- <span class="Identifier">fooItem1</span>
- <span class="Identifier">fooItem2</span>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L243" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L243" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- <div class="section" id="18">
- <h1><a class="toc-backref" href="#18">Templates</a></h1>
- <dl class="item">
- <div id="distinctBase-templates-all">
- <div id="distinctBase.t,T,staticbool">
- <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>
- <dd>
-
- Overload of <a class="reference external" href="#distinctBase,typedesc,static[bool]">distinctBase</a> for values.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Keyword">type</span> <span class="Identifier">MyOtherInt</span> <span class="Operator">=</span> <span class="Keyword">distinct</span> <span class="Identifier">MyInt</span>
- <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>
- <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>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L182" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L182" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="elementType-templates-all">
- <div id="elementType.t,untyped">
- <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>
- <dd>
-
- 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).
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <span class="Keyword">for</span> <span class="Identifier">i</span> <span class="Keyword">in</span> <span class="DecNumber">0</span> <span class="Operator">..<</span> <span class="Identifier">n</span><span class="Punctuation">:</span>
- <span class="Keyword">yield</span> <span class="Identifier">i</span>
- <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>
- <span class="Identifier">doAssert</span> <span class="Identifier">elementType</span><span class="Punctuation">(</span><span class="StringLit">"asdf"</span><span class="Punctuation">)</span> <span class="Keyword">is</span> <span class="Identifier">char</span>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L227" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L227" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="genericParams-templates-all">
- <div id="genericParams.t,typedesc">
- <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>
- <dd>
-
- <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>
- <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>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L313" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L313" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="get-templates-all">
- <div id="get.t,typedesc[],staticint">
- <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>
- <dd>
-
- 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>.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L215" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L215" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="pointerBase-templates-all">
- <div id="pointerBase.t,typedesc[]">
- <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>
- <dd>
-
- 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>.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <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>
- <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">"abc"</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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L123" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L123" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="rangeBase-templates-all">
- <div id="rangeBase.t,T">
- <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>
- <dd>
-
- Overload of <a class="reference external" href="#rangeBase,typedesc,static[bool]">rangeBase</a> for values.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <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>
- <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>
- <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">"int"</span>
- <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>
- <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>
- <span class="Keyword">for</span> <span class="Identifier">e</span> <span class="Keyword">in</span> <span class="Identifier">y</span><span class="Punctuation">:</span>
- <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>
- <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">"MyEnum"</span>
- <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>
- <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>
- <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>
- <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">"char"</span>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L146" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L146" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="toSigned-templates-all">
- <div id="toSigned.t,typedesc[]">
- <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>
- <dd>
-
- Returns a signed type with same bit size as <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <span class="Comment"># range types are currently unsupported:</span>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L364" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L364" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="toUnsigned-templates-all">
- <div id="toUnsigned.t,typedesc[]">
- <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>
- <dd>
-
- Returns an unsigned type with same bit size as <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <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>
- <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>
- <span class="Comment"># range types are currently unsupported:</span>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L349" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L349" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- <div id="tupleLen-templates-all">
- <div id="tupleLen.t">
- <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>
- <dd>
-
- <p>Returns the number of elements of the tuple <tt class="docutils literal"><span class="pre"><span class="Identifier">t</span></span></tt>.</p>
- <p><strong>See also:</strong></p>
- <ul class="simple"><li><a class="reference external" href="#tupleLen,typedesc">tupleLen proc</a></li>
- </ul>
- <p><strong class="examples_text">Example:</strong></p>
- <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>
- <a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L205" class="link-seesrc" target="_blank">Source</a>
- <a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L205" class="link-seesrc" target="_blank" >Edit</a>
- </dd>
- </div>
- </div>
- </dl>
- </div>
- </div>
- </div>
- <div class="twelve-columns footer">
- <span class="nim-sprite"></span>
- <br>
- <small style="color: var(--hint);">Made with Nim. Generated: 2025-02-03 14:57:04 UTC</small>
- </div>
- </div>
- </div>
- <script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
-
- </body>
- </html>
|