isNumeric

Whether the given type is one of the built-in numeric types, ignoring all qualifiers. It's equivalent to isInteger!T || isFloatingPoint!T, but it only involves a single template instantation instead of two.

Numeric Types
byte
ubyte
short
ushort
int
uint
long
ulong
float
double
real

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

enum isNumeric (
T
)

Examples

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

See Also

Meta