isUnsignedInteger

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

Integer Types
ubyte
ushort
uint
ulong

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

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

See also: __traits(isUnsigned, T) isFloatingPoint isInteger isSignedInteger isNumeric

enum isUnsignedInteger (
T
)

Examples

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

Meta