t8829.nim 582 B

12345678910111213141516171819
  1. block:
  2. let txt = "Hello World"
  3. template `[]`[T](p: ptr T, span: Slice[int]): untyped =
  4. toOpenArray(cast[ptr array[0, T]](p)[], span.a, span.b)
  5. doAssert $cast[ptr uint8](txt[0].unsafeAddr)[0 ..< txt.len] ==
  6. "[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]"
  7. block:
  8. let txt = "Hello World"
  9. template `[]`[T](p: ptr T, span: Slice[int]): untyped =
  10. toOpenArray(cast[ptr array[0, T]](p)[], span.a, span.b)
  11. doAssert $cast[ptr uint8](txt[0].unsafeAddr)[0 ..< txt.len] ==
  12. "[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]"