1 /// Simple version of traits from std.traits, for the purpose of faster compile times. 2 module dplug.core.traits; 3 4 // Like `Unqual` but does not remove "shared" or "inout" 5 template RemoveConst(T) 6 { 7 static if (is(T U == immutable U)) 8 alias Unqual = U; 9 else static if (is(T U == const U)) 10 alias Unqual = U; 11 else 12 alias Unqual = T; 13 } 14 15 // faster isIntegral, does not Unqual 16 template isBuiltinIntegral(T) 17 { 18 static if (is(T == int) || is(T == uint) 19 ||is(T == byte) || is(T == ubyte) 20 ||is(T == short) || is(T == ushort) 21 ||is(T == long) || is(T == ulong)) 22 enum bool isBuiltinIntegral = true; 23 else 24 enum bool isBuiltinIntegral = false; 25 } 26 27 // faster isSigned, does not Unqual 28 template isSignedIntegral(T) 29 { 30 enum isSignedIntegral = (is(T == int) || is(T == byte) || is(T == short) || is(T == long)); 31 } 32 33 // faster isUnsigned, does not Unqual 34 template isUnsignedIntegral(T) 35 { 36 enum isUnsignedIntegral = (is(T == uint) || is(T == ubyte) || is(T == ushort) || is(T == ulong)); 37 } 38 39 template UnsignedToSigned(T) 40 { 41 static if (is(T == uint)) 42 alias UnsignedToSigned = int; 43 else static if (is(T == ushort)) 44 alias UnsignedToSigned = short; 45 else static if (is(T == ubyte)) 46 alias UnsignedToSigned = byte; 47 else static if (is(T == ulong)) 48 alias UnsignedToSigned = long; 49 else 50 static assert(false); 51 }