static class Foo{ int i; this(int i)pure nothrow @safe @nogc{ this.i = i; } } static class Bar : Foo{ double d; this(int i, double d)pure nothrow @safe @nogc{ super(i); this.d = d; } } static class Zee{ } { SharedPtr!(const Foo) foo = SharedPtr!Bar.make(42, 3.14); assert(foo.get.i == 42); auto bar = dynCastMove!Bar(foo); assert(foo == null); assert(bar != null); assert(bar.get.d == 3.14); static assert(is(typeof(bar) == SharedPtr!(const Bar))); auto zee = dynCastMove!Zee(bar); assert(zee == null); assert(bar != null); static assert(is(typeof(zee) == SharedPtr!(const Zee))); }
Dynamic cast for shared pointers if ElementType is class with D linkage.
Move instance of SharedPtr whose stored pointer is obtained from ptr's stored pointer using a dynaic cast expression.
If ptr is null or dynamic cast fail then result SharedPtr is null. Otherwise, the new SharedPtr will share ownership with the initial value of ptr.