www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Duplicate class/interface/struct completely

reply Michelle Long <HappyDance321 gmail.com> writes:
Given a class/interface/struct, I'd like to duplicate it's design 
exactly, as if I copied and pasted directly from the source and 
just changed the name. I need to inspect the contents too. Is 
this possible with D?

Main things I'm thinking will fail are (multiple) alias this 
unless there is a way to get which variables are aliased to this.

The idea is to be able to make sure one can modify a class and 
drop it in for the original and it work in all cases. With alias 
this, it can fail unless we can alias it too.

struct X { int y; alias this y; }

struct XX { mixin DupStruct!X; }

If DupStruct cannot handle the alias this then XX can fail to 
mimic X completely.
Mar 25
parent Bastiaan Veelo <Bastiaan Veelo.net> writes:
On Tuesday, 26 March 2019 at 05:29:08 UTC, Michelle Long wrote:
 The idea is to be able to make sure one can modify a class and 
 drop it in for the original and it work in all cases. With 
 alias this, it can fail unless we can alias it too.
This sounds like mocking, this answer might be of help: https://forum.dlang.org/post/gdfvbrknbnbfunycbvwd forum.dlang.org I don’t know the capabilities of these libraries, but you may want to have a look. Bastiaan.
Mar 26