structure inheritance and polymorphism

9il ilyayaroshenko at gmail.com
Mon Jan 4 13:24:51 UTC 2021


On Monday, 4 January 2021 at 01:06:20 UTC, zjh wrote:
> Can d be added with support for structure inheritance and 
> polymorphism?
> I like D, but I don't like GC, so I can't use classes. I can 
> only use betterC. But I want d to have c++ structure 
> inheritance and polymorphism. In this way, I think the 
> competition with c++, the odds are better.

mir.rc.ptr [1] of mir-algorithm package provides thread-safe 
smart pointers that work with structs and classes.

It allows
  * converting a smart pointer to a base class smart pointer.
  * converting a smart pointer to "alias this" struct field.
  * converting a smart pointer to a smart pointer to any struct 
field without additional memory allocation (for structs).


mir.algebraic of mir-core provides [2] algebraic types that 
generate struct accessors if all allowed types have these public 
members. Also, these methods propagation is transparent for 
"alias this" members.

[1] http://mir-algorithm.libmir.org/mir_rc_ptr.html
[2] http://mir-core.libmir.org/mir_algebraic.html#.Algebraic (the 
first big example)

Kind regards,
Ilya





More information about the Digitalmars-d mailing list