I didn't know you could do this, but apparently this works as well (tried on
both 0.18.0 and 0.19.0).
type
MyType = distinct int
template Cast[T](value: typed): T =
cast[T](value)
let a = Cast[int](3.MyType)
echo a
# prints 3
Run
- Trying to learn templates, but its hard to understand. kcvinu
- Re: Trying to learn templates, but its hard to underst... Hlaaftana
- Re: Trying to learn templates, but its hard to und... kcvinu
- Re: Trying to learn templates, but its hard to... kcvinu
- Re: Trying to learn templates, but its har... miran
- Re: Trying to learn templates, but it... juancarlospaco
- Re: Trying to learn templates, bu... jyapayne
- Re: Trying to learn templates... timothee
- Re: Trying to learn templates... kcvinu
- Re: Trying to learn templates... kcvinu
- Re: Trying to learn templates... kcvinu
- Re: Trying to learn templates... kcvinu
- Re: Trying to learn templates... Araq
- Re: Trying to learn templates... kcvinu
- Re: Trying to learn templates... LeuGim
- Re: Trying to learn templates... kaushalmodi
- Re: Trying to learn templates... Araq
