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