import checkedint : SmartInt, SafeInt; alias IFP = IntFlagPolicy; assert(intFlagPolicyOf!(SmartInt!(long, IFP.throws)) == IFP.throws); assert(intFlagPolicyOf!(SafeInt!(uint, IFP.asserts)) == IFP.asserts); assert(intFlagPolicyOf!(SmartInt!(ushort, IFP.sticky)) == IFP.sticky); // basic types implicitly have the `none` policy assert(intFlagPolicyOf!(wchar) == IFP.none); assert(intFlagPolicyOf!(int) == IFP.none); assert(intFlagPolicyOf!(double) == IFP.none); assert(intFlagPolicyOf!(bool) == IFP.none);
intFlagPolicyOf works with custom types, too:
alias IFP = IntFlagPolicy; struct Foo { enum policy = IFP.asserts; } assert(intFlagPolicyOf!Foo == IFP.asserts); struct Bar { // This will be ignored by intFlagPolicyOf, because it has the wrong type: enum policy = 2; } assert(intFlagPolicyOf!Bar == IFP.none);
Get the IntFlagPolicy associated with some type T.