import std/[typetraits, macros] template vecBorrow() {.pragma.} proc isMarked(T: typedesc): bool = hasCustomPragma(T, vecBorrow) type Vec3 = array[3, float32] Color {.vecBorrow.} = distinct Vec3 Point3 {.vecBorrow.} = distinct Vec3 VecOps = concept type V distinctBase(V) is Vec3 V.isMarked proc `[]`[T: VecOps](c: var T, ind: int): var float32 = distinctBase(c)[ind] proc `[]=`[T: VecOps](c: var T, ind: int, val: float32) = distinctBase(c)[ind] = val proc `[]`[T: VecOps](c: T, ind: int): float32 = distinctBase(c)[ind] proc `$`[T: VecOps](c: T): string = $distinctBase(c) var a = Color Vec3([1f, 2, 3]) a[0] = 300 echo a[0] echo a # For a maddening example