Walter's second axiom

Jason House jason.james.house at gmail.com
Tue Dec 11 15:57:17 PST 2007


Walter Bright wrote:
> That axiom didn't really exist until Andrei started pointing out to me
> all the advantages of being able to wrap types in a struct. So we can
> expect some historical problems with it.

Can you please share with us all the advantages of "Any type T can be
wrapped inside a struct S, and that S can be made to behave as a typedef
for type T."


Under what conditions can it behave exactly like a typedef?  If it behaves
*exactly* as a typedef under all circumstances, then it can't have any
additional data members or member functions and must behave exactly like
the original.  If that's true, why wrap it in a struct at all?

I assume there has to be some way to bend that.  Candidates in my mind are
extra data members and extra member functions.  Extra data members seems
less likely because a cast from S to T and back to S would lose data
(something that typedef's don't have happen).  Of course, this may fit into
the grand scheme of opImplicitCast.

I also wonder if extending a class may be an alternative to wrapping it in a
struct.  Maybe wrapping in a struct could be restricted to value types?  I
just don't understand this enough yet to give any credible suggestions.



More information about the Digitalmars-d mailing list