t8829.nim 578 B

12345678910111213141516171819
  1. block:
  2. let txt = "Hello World"
  3. template `[]`[T](p: ptr T, span: Slice[int]): untyped =
  4. toOpenArray(cast[ptr UncheckedArray[T]](p), span.a, span.b)
  5. doAssert $cast[ptr uint8](txt[0].addr)[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 UncheckedArray[T]](p), span.a, span.b)
  11. doAssert $cast[ptr uint8](txt[0].addr)[0 ..< txt.len] ==
  12. "[72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]"