Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check, if the type is unsigned or not?

Tags:

d

I want check, if the type is byte/short/int/long or it is ubyte/ushort/uint/ulong. The first idea was to use construction is(T1:T2), but is(ulong:long)==is(long:ulong)==true, so it is not the way.

Now I'm using something like is(T:long) && (cast(T)(-1)<cast(T)(1)), but this code seems ugly to me.

So is there more elegant logic statement returning true only if the type is unsigned?

like image 710
Timushev Roman Avatar asked Dec 26 '13 14:12

Timushev Roman


1 Answers

There is a template in std.traits that does what you want: http://dlang.org/phobos/std_traits.html#.isUnsigned

Use it like:

if(isUnsigned!T1) {
    //...
}
like image 50
Chris Cain Avatar answered Sep 20 '22 22:09

Chris Cain