How to test for equality of types?
Philippe Sigaud
philippe.sigaud at gmail.com
Sat May 19 06:28:00 PDT 2012
On Sat, May 19, 2012 at 12:23 PM, Matthias Walter
<xammy at xammy.homelinux.net> wrote:
> I would open a bug report with the following code which is a bit smaller
> than my first wrong version:
>
> =====================
(...)
> pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> "MyStruct"
> pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
> static assert(is(typeof(w.aliasStruct) == AliasStruct)); // -> true
> static assert(is(typeof(w.aliasStruct).Alias == AliasStruct.Alias));
> // -> false
> }
Seems like a pb concerning whether Alias is a type or a symbol. See
A,B,C,D below:
void main()
{
Wrapper w;
pragma(msg, typeof(w.aliasStruct).Alias.stringof); // -> "MyStruct"
pragma(msg, AliasStruct.Alias.stringof); // -> "MyStruct"
static assert(is(typeof(w.aliasStruct) == AliasStruct)); // -> true
static assert(is(w.aliasStruct.Alias == AliasStruct.Alias)); // -> true
alias typeof(w.aliasStruct) A; // -> OK
//alias typeof(w.aliasStruct).Alias B; // -> NOK
//alias A.Alias C; // -> NOK
alias w.aliasStruct.Alias D; // -> OK
static assert(is(A.Alias == AliasStruct.Alias)); // -> true
//static assert(is(B == AliasStruct.Alias));
//static assert(is(C == AliasStruct.Alias));
static assert(is(D == AliasStruct.Alias)); // -> true
}
I think A is enough for your need, but I don't get why B and C are not
accepted (DMD 2.059, Linux)
More information about the Digitalmars-d-learn
mailing list