blob: 3ffa65e582ed1c6218bba2d3181ca62408dd8d60 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
discard """
output: "1"
"""
type
TMyTuple = tuple[a, b: int]
proc indexOf*(t: typedesc, name: string): int {.compiletime.} =
## takes a tuple and looks for the field by name.
## returs index of that field.
var
d: t
i = 0
for n, x in fieldPairs(d):
if n == name: return i
i.inc
raise newException(EInvalidValue, "No field " & name & " in type " &
astToStr(t))
echo TMyTuple.indexOf("b")
|