isPointer

Whether the given type is a pointer.

Note that this does not include implicit conversions or enum types. The type itself must be a pointer.

Also, remember that unlike C/C++, D's arrays are not pointers. Rather, a dynamic array in D is a slice of memory which has a member which is a pointer to its first element and another member which is the length of the array as size_t. So, a dynamic array / slice has a ptr member which is a pointer, but the dynamic array itself is not a pointer.

enum isPointer (
T
)

Examples

1 // Some types which are pointers.
2 static assert( isPointer!(bool*));
3 static assert( isPointer!(int*));
4 static assert( isPointer!(int**));
5 static assert( isPointer!(real*));
6 static assert( isPointer!(string*));
7 
8 static assert( isPointer!(const int*));
9 static assert( isPointer!(immutable int*));
10 static assert( isPointer!(inout int*));
11 static assert( isPointer!(shared int*));
12 static assert( isPointer!(const shared int*));
13 
14 static assert( isPointer!(typeof("foobar".ptr)));
15 
16 int* ptr;
17 static assert( isPointer!(typeof(ptr)));
18 
19 int i;
20 static assert( isPointer!(typeof(&i)));
21 
22 // Some types which aren't pointers.
23 static assert(!isPointer!bool);
24 static assert(!isPointer!int);
25 static assert(!isPointer!dchar);
26 static assert(!isPointer!(int[]));
27 static assert(!isPointer!(double[4]));
28 static assert(!isPointer!string);
29 
30 static struct S
31 {
32     int* ptr;
33 }
34 static assert(!isPointer!S);
35 
36 // The struct itself isn't considered a numeric type,
37 // but its member variable is when checked directly.
38 static assert( isPointer!(typeof(S.ptr)));
39 
40 enum E : immutable(char*)
41 {
42     a = "foobar".ptr
43 }
44 
45 // Enums do not count.
46 static assert(!isPointer!E);
47 
48 static struct AliasThis
49 {
50     int* ptr;
51     alias this = ptr;
52 }
53 
54 // Other implicit conversions do not count.
55 static assert(!isPointer!AliasThis);

See Also

Meta