On 4/21/17 8:17 AM, Andrei Alexandrescu wrote:
On 04/20/2017 04:35 PM, Carl Sturtivant wrote:
On Wednesday, 19 April 2017 at 18:32:43 UTC, Carl Sturtivant wrote:
Imagine the existing single `alias this` is extended to provide such a
heierarchy of lookups. For example,
struct top
{
mem3 m3;
mem2 m2;
mem1 m1;
alias m3, m2, m1 this;
// ...
}
could be interpreted to mean search for a name in m3 if not found in
top, and in m2 if not found in m3 and in m1 if not found in m2. I
don't back the syntax, just the notion.
Maybe that's not all that's expected from "multiple alias this" but it
would be a clean step forward. Issues?
No issues then!
Time for a D I P perhaps.
Comment?
This is interesting, and would be timely to discuss before an
implementation of multiple alias this gets started. -- Andrei
I agree, I like how this solves the ambiguity problem nicely. However,
this disallows using introspection to declare multiple alias this
piecemeal. e.g.:
struct S(bool foo)
{
int x;
alias x this;
static if(foo)
{
string y;
alias y this;
}
}
One thing we can do also is just use declaration order to prioritize
which alias this to use.
-Steve