isType

Evaluates to true if given a type and false for all other symbols.

This is equivalent to is(T), but some people may find using a named trait to be clearer, and it can be used in conjunction with templates that take a template predicate (such as those in phobos.sys.meta), which can't be done with naked is expressions.

  1. eponymoustemplate isType(T)
  2. eponymoustemplate isType(alias sym)
    enum isType (
    alias sym
    )

Examples

1 static assert( isType!int);
2 static assert( isType!(int[]));
3 static assert( isType!string);
4 static assert( isType!(int[int]));
5 static assert( isType!(ubyte*));
6 static assert( isType!void);
7 
8 int i;
9 static assert(!isType!i);
10 static assert( isType!(typeof(i)));
11 
12 struct S {}
13 static assert( isType!S);
14 static assert(!isType!(S.init));
15 
16 class C {}
17 static assert( isType!C);
18 static assert(!isType!(C.init));
19 
20 interface I {}
21 static assert( isType!I);
22 static assert(!isType!(I.init));
23 
24 union U {}
25 static assert( isType!U);
26 static assert(!isType!(U.init));
27 
28 static void func() {}
29 static assert(!isType!func);
30 static assert( isType!(typeof(func)));
31 
32 void funcWithContext() { ++i; }
33 static assert(!isType!funcWithContext);
34 static assert( isType!(typeof(funcWithContext)));
35 
36 int function() funcPtr;
37 static assert(!isType!funcPtr);
38 static assert( isType!(typeof(funcPtr)));
39 
40 int delegate() del;
41 static assert(!isType!del);
42 static assert( isType!(typeof(del)));
43 
44 template Templ() {}
45 static assert(!isType!Templ);
46 static assert(!isType!(Templ!()));
47 
48 template TemplWithType()
49 {
50     struct S {}
51 }
52 static assert(!isType!TemplWithType);
53 static assert(!isType!(TemplWithType!()));
54 static assert( isType!(TemplWithType!().S));
55 
56 struct TemplType() {}
57 static assert(!isType!TemplType);
58 static assert( isType!(TemplType!()));

See Also

Meta