I use this: int ToInt(in ulong u) pure { assert(u<=int.max); return cast(int)u; } int Count(E)(in E[] arr) pure { return ToInt(arr.length); } Well, it depends if you're fine with just an assert.