www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - is expression: library reference

reply Morlan <home valentimex.com> writes:
The library refernce has the following text concerning the is expression:

5. is ( Type Identifier : TypeSpecialization )

The condition is satisfied if Type is the same as TypeSpecialization, or if
Type is a class and TypeSpecialization is a base class or base interface of
it. The Identifier is declared to be either an alias of the TypeSpecialization
or, if TypeSpecialization is dependent on Identifier, the deduced type.

However, the following code fragment will print "short is int" and "short"
which seems to contradict the above description.

  static if(is(short T: int)){
    writeln("short is int");
    writeln(typeid(T));
  }else{
    writeln("short is not int");
  }

The observed behaviour is such that short T: int means that short can be
implicitely converted to int and T is defined to mean "short" rather than
"int". Thus T is not defined to mean TypeSpecialization but Type. This
discrepancy should be corrected.
Mar 24 2011
parent Jonathan M Davis <jmdavisProg gmx.com> writes:
 The library refernce has the following text concerning the is expression:
 
 5. is ( Type Identifier : TypeSpecialization )
 
 The condition is satisfied if Type is the same as TypeSpecialization, or if
 Type is a class and TypeSpecialization is a base class or base interface of
 it. The Identifier is declared to be either an alias of the
 TypeSpecialization or, if TypeSpecialization is dependent on Identifier,
 the deduced type.
 
 However, the following code fragment will print "short is int" and "short"
 which seems to contradict the above description.
 
   static if(is(short T: int)){
     writeln("short is int");
     writeln(typeid(T));
   }else{
     writeln("short is not int");
   }
 
 The observed behaviour is such that short T: int means that short can be
 implicitely converted to int and T is defined to mean "short" rather than
 "int". Thus T is not defined to mean TypeSpecialization but Type. This
 discrepancy should be corrected.

Create a bug report for it: http://d.puremagic.com/issues/ - Jonathan M Davis
Mar 24 2011