Why does the following code fail to compile if the `writeln(value);` line is present?

public template ForeachAggregate(T)
{
        alias ForeachAggregate = int delegate(ref T) nothrow;
}

unittest
{
        import std.stdio;

        class Foo
        {
                private string[] _data = ["foo", "bar", "baz", "qux"];

                public int opApply(ForeachAggregate!(string) dg) nothrow
                {
                        int result;

                        for (int x = 0; x < this._data.length; x++)
                        {
                                result = dg(this._data[x]);

                                if (result)
                                {
                                        break;
                                }
                        }

                        return result;
                }
        }

        auto foo = new Foo();

        foreach (string value; foo)
        {
                writeln(value);
        }
}

Reply via email to