Unexpected result of IsInstanceOf

Ali Çehreli acehreli at yahoo.com
Fri Jan 31 01:16:46 UTC 2020


On 1/30/20 4:51 PM, Ben Jones wrote:
> The following result doesn't make sense to me... how does isInstanceOf 
> return false?
> 
> ```
> import std.traits;
> import std.stdio;
> import std.typecons;
> auto f(T)(T t){
>      return Nullable!T(t);
> }
> void main(){
>      auto f3 = f(3);
>      writeln(typeof(f3).stringof);
>      writeln(isInstanceOf!(Nullable, f3));
> }
> ```
> 
> outputs
> 
> ```
> Nullable!int
> false
> ```

In this case it's an instance of a type template, which only types would 
be. So, you want to check whether typeof(f3) is an instance of Nullable.

Ali




More information about the Digitalmars-d-learn mailing list