How to test for equality of types?

Artur Skawina art.08.09 at gmail.com
Fri May 18 14:59:05 PDT 2012


On 05/18/12 23:06, Matthias Walter wrote:
> =============
> 
> struct MyStruct { }
> 
> struct Wrapper(Wrap)
> {
>   Wrap _wrap;
> 
>   this(Wrap wrap)
>   {
>     _wrap = wrap;
>   }
> }
> 
> 
> struct AliasStruct
> {
> public:
>   alias MyStruct Alias;
> }
> 
> 
> int main(char[][] args)
> {
>   auto w = Wrapper!(AliasStruct)(AliasStruct.init);
>   pragma(msg, is(Wrapper!(AliasStruct).Wrap == AliasStruct) ? "true" :
> "false");
>   pragma(msg, is(typeof(w._wrap) == AliasStruct) ? "true" : "false");
>   pragma(msg, is(typeof(w._wrap).Alias == AliasStruct.Alias) ? "true" :
> "false");
> 
> 
>   return 0;
> }
> =============
> 
> prints out
> 
> false
> true
> false
> 
> during compilation using current git version of dmd. In my application I
> used the third case, i.e., wanted to find out whether they alias the
> same thing.

Hmm, my old GDC considers them equal (ie last line is "true"), so it's a recent
change. What does

  pragma(msg, is(w._wrap.Alias == AliasStruct.Alias));
  pragma(msg, typeof(w._wrap).Alias.stringof);
  pragma(msg, AliasStruct.Alias.stringof);

print?

Looks like a bug.

artur


More information about the Digitalmars-d-learn mailing list