Files
Nim/typetraits.html
github-actions[bot] c7440eccf2 Deploy to GitHub pages
2025-09-27 04:02:34 +00:00

738 lines
86 KiB
HTML

<?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:&nbsp;</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>
<li>
<a class="reference reference-toplevel" href="#19" id="69">Exports</a>
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L1" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L22" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L23" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L223" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<dd>
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.
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L45" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L167" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L54" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L341" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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">&quot;strictNotNil&quot;</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L99" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L116" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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">&quot;int&quot;</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">&quot;seq[string]&quot;</span></pre>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L37" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L37" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L133" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L84" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L94" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L196" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L243" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L182" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">..&lt;</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">&quot;asdf&quot;</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L227" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L313" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L215" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&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>
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/typetraits.nim#L123" class="link-seesrc" target="_blank">Source</a>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L123" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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">&quot;int&quot;</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">&quot;MyEnum&quot;</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">&quot;char&quot;</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L146" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L364" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L349" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</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>&nbsp;&nbsp;
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/typetraits.nim#L205" class="link-seesrc" target="_blank" >Edit</a>&nbsp;&nbsp;
</dd>
</div>
</div>
</dl>
</div>
<div class="section" id="19">
<h1><a class="toc-backref" href="#19">Exports</a></h1>
<dl class="item">
<a href="dollars.html#$,uint"><span class="Identifier">$</span></a>, <a href="dollars.html#$,typedesc"><span class="Identifier">$</span></a>, <a href="dollars.html#$,openArray[T]"><span class="Identifier">$</span></a>, <a href="dollars.html#$"><span class="Identifier">$</span></a>, <a href="dollars.html#$,char"><span class="Identifier">$</span></a>, <a href="dollars.html#$,HSlice[T,U]"><span class="Identifier">$</span></a>, <a href="dollars.html#$,uint32"><span class="Identifier">$</span></a>, <a href="dollars.html#$,Enum"><span class="Identifier">$</span></a>, <a href="dollars.html#$,uint64"><span class="Identifier">$</span></a>, <a href="dollars.html#$_2"><span class="Identifier">$</span></a>, <a href="dollars.html#$,array[IDX,T]"><span class="Identifier">$</span></a>, <a href="dollars.html#$,int64"><span class="Identifier">$</span></a>, <a href="dollars.html#$,string"><span class="Identifier">$</span></a>, <a href="dollars.html#$,int"><span class="Identifier">$</span></a>, <a href="dollars.html#$,int8"><span class="Identifier">$</span></a>, <a href="dollars.html#$,int32"><span class="Identifier">$</span></a>, <a href="dollars.html#$,uint16"><span class="Identifier">$</span></a>, <a href="dollars.html#$,set[T]"><span class="Identifier">$</span></a>, <a href="dollars.html#$,int16"><span class="Identifier">$</span></a>, <a href="dollars.html#$,uint8"><span class="Identifier">$</span></a>, <a href="dollars.html#$,seq[T]"><span class="Identifier">$</span></a>, <a href="dollars.html#$_3"><span class="Identifier">$</span></a>, <a href="dollars.html#$,T"><span class="Identifier">$</span></a>, <a href="dollars.html#$,bool"><span class="Identifier">$</span></a>, <a href="dollars.html#$,cstring"><span class="Identifier">$</span></a>
</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-09-27 04:01:54 UTC</small>
</div>
</div>
</div>
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
</body>
</html>