Using Nim Types in Constructors

Created on 2022-06-16T20:50:07-05:00

Return to the Index

This card can also be read via Gemini.

Typedesc can be used as a parameter. This allows (via universal function call syntax) you to pretend you are asking the type to instantiate itself (or any other operation.) In theory since the parameter is then not used for anything and the function is inlined there is no overhead in the final product.

proc make*(not_used: typedesc[Thing]) {.inline.} = ...

foo = Thing.make