Limited Semi-PolyMorphic (LSP) structs?

Era Scarecrow rtcvb32 at yahoo.com
Wed Aug 28 14:24:54 PDT 2013


On Wednesday, 28 August 2013 at 15:20:34 UTC, Artur Skawina wrote:
> It's hard to tell what your actual requirements are; this 
> discriminated union might help. It does a bit more than what 
> you ask for, as it also gives access to /data/, not just 
> methods; this shouldn't be a problem.

  Requirements, I don't have any written down but I have it in my 
head. I want to replace specific functions, I don't want to use a 
vTable (or pointer or anything like that). They are replaced 
based on fixed criteria of what the changed behavior is/needs to 
be.

  I want to use OO and inheritance to split it into logical 
portions (after sorta implementing inheritance/semi-polymorphism 
in pure C functions the code got ugly fast and is difficult to 
navigate through).


> The data access parts could be even more efficient, but I 
> failed to figure out a way to check for perfectly overlapping 
> fields at CT - offsetof doesn't work after an alias-this 
> conversion takes place, CTFE does not allow the pointer 
> arithmetic required, and when ctfe does, the result can be 
> false negatives. Maybe someone else has an idea how to 
> correctly implement the 'atSameOff' function below (which would 
> make accesses to compatible data members free; right now the 
> type check is never omitted. It could also be done using manual 
> annotations, but those shouldn't be necessary...)

  It looks like I'll have to read this in more detail when I can 
wrap my head around it. I'll give it a look.


More information about the Digitalmars-d-learn mailing list