Limited Semi-PolyMorphic (LSP) structs?

Era Scarecrow rtcvb32 at yahoo.com
Mon Aug 26 06:03:15 PDT 2013


On Monday, 26 August 2013 at 12:42:43 UTC, qznc wrote:
> Hm, my try would be alias this for inheritance and function 
> pointers for virtual methods.
>
> struct iA {
>   void function(iA) A;
>   void C();
> }
>
> struct iB {
>   iA _a;
>   alias this = _a;
>   void B();
> }
>
> If you have multiple "subclasses" for iA, you can use a 
> tagged-union from std.variant.


  Hmmm. I haven't considered std.variant, and glancing at it 
(although I'll have to be more in depth later) it doesn't look 
like what I'm really going for.

  Besides the iA and iB are far too simplistic compared to what I 
really need to do. For the subclasses there's at least 10, some 
of it's just for comparison/ordering, but some of it is for 
pre/post operations. Let's see...

  HEDR (Header information)
  NAME (raw text)
  DATA (raw, or location x,y,z, or a mapping, etc)
  SCPT (text Script data)
  ENAM (data...)
  FLAG (data, search/handling different)
  NPCO (string, of item)
  NPCS (string, of spell)
  FRMR (Object id)
  INAM (ID for dialog)
  PNAM (linked list, previous dialog)
  NNAM (linked list, next dialog)

  These are just a few of them, Data actually has like 15+ entries 
although only a few of them require special cases. multiple alias 
this's won't work. There's also multiple cases where the 
override/subclass is merely to generate the NAME (or ID entry) 
differently ( partially for sorting but mostly informational 
purposes) so it may reference the original object but I don't 
want to have to do a bunch of forced casts (and clutter up code).


More information about the Digitalmars-d-learn mailing list