No description
Find a file
sls1005 4cb082f83b typo
2022-11-23 14:25:40 +08:00
src remove unnecessary pragmas 2022-10-24 17:05:41 +08:00
tests The generic parameter of the 2nd overload of dynamicCast is changed from var object to object. This change is not backward-compatible. 2022-10-23 18:47:36 +08:00
casting.nimble typo 2022-11-23 14:25:40 +08:00
LICENSE Add many files 2022-10-21 17:49:15 +08:00
README.md remove unnecessary pragmas 2022-10-24 17:05:41 +08:00

Casting

This wraps the C++ cast operators for the Nim programming language.

Example

from casting import dynamicCast
type
  A {.inheritable, pure.} = object
    a: int
  B = object of A
    b: float
var x: B
let p: ptr A = dynamicCast[ptr A](x.addr)
if p.isNil():
  echo "failed to cast"
else:
  (p[]).a = 1
  assert x.a == 1

Note

  • Please use the built-in keyword cast if possible. This wrapper should only be used where cast fails, or is inappropriate to use.

Warning

  • Some of the procs provided by this package allow performing unsafe operations. Please be sure of knowing what you are doing with them.

Reference