nim-lang-utils/langutils.nim
2016-10-07 20:11:53 -05:00

20 lines
374 B
Nim

template `?:`*(a, b: string): string =
if len(a) > 0: a else: b
template `?:`*(a: object, b: string): string =
if a: $a else: b
template `?:`*(a: ref, b): auto =
if a != nil: a else: b
template `?:`*(a, b: object): object =
if a: a else: b
template `?:`*(a, b): auto =
if a: a else: b
template `?.`*(a: ref, b: untyped): auto =
if a != nil: a.b else: nil