Nested Structs (Solution)
js.mdnq
js_adddot+mdng at gmail.com
Thu Dec 13 22:45:55 PST 2012
On Friday, 14 December 2012 at 06:27:39 UTC, Rob T wrote:
> I guess the complicating factor is that a nested struct could
> not be copied out of one class into another of a different
> type, so I can see why it's not implemented. The compiler would
> have to prevent copies out, or the language would have to be
> modified to allow nesting but with some new convention to make
> it clear that the struct is nested, not sure if it's worth it
> though, you can always make do without it.
>
> --rt
This is why I suggested a new type earlier so that it is obvious
something is different. Since my initial reason for needed such a
structure was to wrap built in types to provide functionality
it's not a big deal because one can override opAssign and use
alias this. Doing so basically lets the "outside world" use the
type as if it were the value type and when copied they are
copying the built in types rather than the structs.
If it's a big deal it is not hard to create a duplicate struct
with the added outer pointer similar to what is done with nested
classes and then just copy over the data from one to the other.
This will work fine except the need to create two structs with
different, although, now that I think about it, I could
potentially use a static if to create such a dual struct which
would then help avoid orphans.
When an assignment from the struct is used it will return, not
itself, but either it's value(if a wrapper) or this new struct
which is identical except containing a ptr to it's parent. I'll
try to add it and see how it works.
More information about the Digitalmars-d
mailing list