1 /** 2 Copyright: Copyright Thomas Stuart Bockman 2015 3 License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>. 4 Authors: Thomas Stuart Bockman 5 */ 6 7 module future.traits; 8 9 public import std.traits; 10 static if(__VERSION__ < 2068) 11 alias CopyTypeQualifiers(From, To) = To; // HACK! 12 else { 13 version(GNU) { static assert(false); } 14 } 15 16 enum isUnqual(T) = is(T == Unqual!T); 17 enum isFixedPoint(T) = isIntegral!T || isSomeChar!T || isBoolean!T; 18 19 template IntFromChar(N) 20 if(isSomeChar!N) 21 { 22 static if(N.sizeof == char.sizeof) 23 alias IntFromChar = ubyte; 24 else 25 static if(N.sizeof == wchar.sizeof) 26 alias IntFromChar = ushort; 27 else 28 static if(N.sizeof == dchar.sizeof) 29 alias IntFromChar = uint; 30 else 31 static assert(false); 32 } 33 template IntFromChar(N) 34 if(isIntegral!N) 35 { 36 alias IntFromChar = Unqual!N; 37 } 38 template Promoted(N) 39 if(isScalarType!N) 40 { 41 alias Promoted = CopyTypeQualifiers!(N, typeof(N.init + N.init)); 42 } 43 44 alias CallType(alias callable, ArgTypes...) = typeof(function() { 45 import std.typecons : Tuple; 46 return callable(Tuple!(ArgTypes)().expand); 47 }()); 48 alias OpType(string op, T) = typeof(function() { 49 T t; 50 return mixin(op ~ "t"); 51 }()); 52 alias OpType(T, string op, V) = typeof(function() { 53 T t; 54 V v = 1; // Prevent "divide by zero" errors at CTFE 55 return mixin("t " ~ op ~ " v"); 56 }()); 57 58 template precision(N) 59 if(isScalarType!N) 60 { 61 import future.bitop : bsr; 62 static if(isFloatingPoint!N) 63 enum precision = N.mant_dig; 64 else static if(isSomeChar!N) 65 enum precision = N.sizeof * 8; // dchar may hold values greater than dchar.max 66 else 67 enum precision = bsr(N.max) + 1; 68 }