Debugging tip: Templates should almost never be marked @safe or @trusted, as the safety should be inferred. However, to isolate down where the unsafe code actually is, add @safe temporarily to the template declaration. Then, the compiler will tell you which line in the template is unsafe.