1 module cushion._internal.misc; 2 3 package(cushion): 4 5 // If name member of x is exists, this template returns that member otherwise returns defaultVal 6 template getMemberAlias(alias x, string name, defaultVal...) 7 { 8 static if (__traits(hasMember, x, name)) 9 alias getMemberAlias = __traits(getMember, x, name); 10 else 11 alias getMemberAlias = defaultVal[0]; 12 } 13 14 /// ditto 15 template getMemberValue(alias x, string name, defaultVal...) 16 { 17 static if (__traits(hasMember, x, name)) 18 enum getMemberValue = __traits(getMember, x, name); 19 else 20 enum getMemberValue = defaultVal[0]; 21 } 22 23 24 // 25 pragma(inline) T trustedCast(T, Arg)(Arg arg) @trusted 26 { 27 return cast(T)arg; 28 }