www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - is is cast on hash required

reply "Dan" <dbdavidson yahoo.com> writes:
Is there a way around the cast below to see if ci is i?
If not, is there already a standard template method that does 
DeepUnqual.
Finally, if not a workaround is this safe?

Thanks
Dan
----------------------
import std.traits;

void main() {
   const(int[string]) ci;
   int[string] i;
   // FAILS TO COMPILE if(ci is i) { }
   if(cast(DeepUnqual!(typeof(ci)))ci is 
cast(DeepUnqual!(typeof(i)))i) {  }
}

template DeepUnqual(T) {
   static if(isAssociativeArray!T) {
     alias Unqual!(Unqual!(ValueType!T)[Unqual!(KeyType!T)]) 
DeepUnqual;
   } else static if(isDynamicArray!T) {
     alias Unqual!(Unqual!(ArrayElementType!T)[]) DeepUnqual;
   } else static if(isPointer!T) {
     alias Unqual!(PointerTarget!T) * DeepUnqual;
   } else {
     alias Unqual!T DeepUnqual;
   }
}
Nov 15 2012
parent "bearophile" <bearophileHUGS lycos.com> writes:
Dan:

 Is there a way around the cast below to see if ci is i?
I have added a related bug report: http://d.puremagic.com/issues/show_bug.cgi?id=9031 Bye, bearophile
Nov 15 2012