https://issues.dlang.org/show_bug.cgi?id=23666
--- Comment #3 from Bolpat <[email protected]> --- (In reply to Nick Treleaven from comment #2) > You can use `auto opApply` to infer attributes instead of a template. ```d struct S { auto opApply(int delegate(ref int) callback) { int x; return callback(x); } } void main() @safe { foreach (ref x; S()) {} // Error: `@safe` function `D main` cannot call `@system` function `S.opApply` } ``` However, this does (for reasons beyond my understanding): ```d struct S { int opApplyImpl(DG : int delegate(ref int))(scope DG callback) { int x; return callback(x); } alias opApply = opApplyImpl!(int delegate(ref int)); } void main() @safe { foreach (ref x; S()) {} } ``` --
