isInteger

Whether the given type is one of the built-in integer types, ignoring all qualifiers.

Integer Types
byte
ubyte
short
ushort
int
uint
long
ulong

Note that this does not include implicit conversions or enum types. The type itself must be one of the built-in integer types.

This trait does have some similarities with __traits(isIntegral, T), but isIntegral accepts a lot more types than isInteger does. isInteger is specifically for testing for the built-in integer types, whereas isIntegral tests for a whole set of types that are vaguely integer-like (including bool, the three built-in character types, and some of the vector types from core.simd). So, for most code, isInteger is going to be more appropriate, but obviously, it depends on what the code is trying to do.

See also: __traits(isIntegral, T) isFloatingPoint isSignedInteger isNumeric isUnsignedInteger

enum isInteger (
T
)

Examples

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

Meta