[Issue 11124] support "is (T : struct)" syntax

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 25 12:23:06 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=11124



--- Comment #7 from monarchdodra at gmail.com 2013-09-25 12:23:05 PDT ---
(In reply to comment #6)
> (In reply to comment #4)
> > (In reply to comment #2)
> > > And, how this will work when multiple alias this is properly implemented?
> > 
> > I don't understand the problem? Isn't it the same as, say: "is (C : int)"?
> 
> Today,
> 1. is(T U == super) captures the super class list of T in U.
> 
>   class C : Object {}
>   static if (is(C U == super)) { static assert(is(U[0] == Object)); }
> 
> 2. If T is implicitly convertible to U, is(T X : U) captures T in X.
> 
> Then, if multiple alias this is supported:
> 
>   struct S1 {}
>   struct S2 {}
>   struct S {
>     S1 s1;  alias s1 this;
>     S2 s2;  alias s2 this;
>   }
>   static if (is(S U : struct)) { /* What's captured in U? */ }
> 
> Based on the #1, U would capture the tuple of S1 and S2.
> Based on the #2, U would capture the type S.
> 
> Which is chosen? Or other choices?

I'm no expert with "is", but isn't "is(C U == super)" a special case of "is"?
(which would look much better as a trait too?)

For example, when I do this;

//----
struct S
{
    short i;
    alias i this;
}

class C
{
    S s;
    alias s this;
}

void main()
{
    static if (is(C U : int))
        static assert(is(U == C)); //Base type C is captured
}
//----

If C was to actually to be:

class C
{
    S s1;
    S s2;
    alias s1 this;
    alias s2 this;
}

I don't see how it would affect my above static if.

Since I don't really see ": int" as any different from ": struct", then to your
question, I answer: #2, U would capture the type S.

But I'm no "is" expert.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list