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