1 /** 2 Compatibility shim to allow code written against the latest `std.traits` 3 module to compile with older versions of D. 4 5 Copyright: Copyright Thomas Stuart Bockman 2015 6 License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0). 7 Authors: Thomas Stuart Bockman 8 **/ 9 10 /* HACK: Added '0' to the end of the name to preventdub build -b docs 11 from overwriting the output of checkedint.traits */ 12 module future.traits0; 13 14 public import std.traits; 15 static if (__VERSION__ < 2068) 16 alias CopyTypeQualifiers(From, To) = To; // HACK! 17 else 18 { 19 version(GNU) { static assert(false); } 20 } 21 22 enum isUnqual(T) = is(T == Unqual!T); 23 enum isFixedPoint(T) = isIntegral!T || isSomeChar!T || isBoolean!T; 24 25 template IntFromChar(N) 26 if (isSomeChar!N) 27 { 28 static if (N.sizeof == char.sizeof) 29 alias IntFromChar = ubyte; 30 else 31 static if (N.sizeof == wchar.sizeof) 32 alias IntFromChar = ushort; 33 else 34 static if (N.sizeof == dchar.sizeof) 35 alias IntFromChar = uint; 36 else 37 static assert(false); 38 } 39 template IntFromChar(N) 40 if (isIntegral!N) 41 { 42 alias IntFromChar = Unqual!N; 43 } 44 template Promoted(N) 45 if (isScalarType!N) 46 { 47 alias Promoted = CopyTypeQualifiers!(N, typeof(N.init + N.init)); 48 } 49 50 alias CallType(alias callable, ArgTypes...) = typeof(function() 51 { 52 import std.typecons : Tuple; 53 return callable(Tuple!(ArgTypes)().expand); 54 }()); 55 alias OpType(string op, T) = typeof(function() 56 { 57 T t; 58 return mixin(op ~ "t"); 59 }()); 60 alias OpType(T, string op, V) = typeof(function() 61 { 62 T t; 63 V v = 1; // Prevent "divide by zero" errors at CTFE 64 return mixin("t " ~ op ~ " v"); 65 }()); 66 67 template precision(N) 68 if (isScalarType!N) 69 { 70 import future.bitop : bsr; 71 static if (isFloatingPoint!N) 72 enum int precision = N.mant_dig; 73 else static if (isSomeChar!N) 74 enum int precision = N.sizeof * 8; // dchar may hold values greater than dchar.max 75 else 76 enum int precision = bsr(N.max) + 1; 77 }